test(proxy): stop monkeypatch.undo re-planting fixture-mocked prisma_client - #36872
Merged
mateo-berri merged 1 commit intoAug 14, 2026
Merged
Conversation
Contributor
Greptile SummaryThe PR replaces fixture-based proxy-global isolation with setup and teardown hooks so restoration occurs after fixture finalizers
Confidence Score: 5/5The PR appears safe to merge No blocking failure remains
|
| Filename | Overview |
|---|---|
| tests/test_litellm/proxy/conftest.py | Moves proxy-global snapshot and restoration into pytest hookwrappers so monkeypatch teardown cannot reintroduce fixture mocks |
| tests/test_litellm/proxy/management_endpoints/test_mcp_management_endpoints.py | Pins three MCP management tests to the no-database branch by mocking the Prisma accessor |
| tests/test_litellm/proxy/test_conftest.py | Adds a focused regression pair proving a fixture-planted Prisma mock does not leak into the next test |
Reviews (2): Last reviewed commit: "test(proxy): stop monkeypatch.undo re-pl..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Author
shin-berri
approved these changes
Aug 14, 2026
shin-berri
left a comment
Collaborator
There was a problem hiding this comment.
This blocks CI. Self-approving safe test-only change
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TLDR
Problem this solves:
How it solves it:
The mechanism: the root conftest's autouse fixtures request monkeypatch, so monkeypatch's undo stack unwinds after every other fixture finalizer. test_team_endpoints.py has an autouse fixture that patches litellm.proxy.proxy_server.prisma_client with a MagicMock, and its delete_team tests monkeypatch that same global, recording the fixture's mock as the "original". At teardown the patch exits, the old isolation fixture restores the real value, and then monkeypatch.undo runs last and re-plants the MagicMock. Every later test's snapshot faithfully preserves it, so the worker is poisoned for the rest of the session and any later no-database MCP test that reads the global takes the database path and fails awaiting a MagicMock. With xdist loadscope this repeats whenever the team and MCP modules share a worker, which is why reruns fail identically
User Flow
Before: a contributor's PR that never touches proxy code fails the required proxy-endpoints check, and re-running fails the same way
TypeError: object MagicMock can't be used in 'await' expression, having already survived the job's two automatic per-test retriesAfter: the same PR passes the proxy-endpoints check on the first run
Relevant issues
Unblocks the required check failing on #36864
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
This PR changes only test isolation, so the end-to-end surface is the CI job itself rather than a live proxy route. The failing check is deterministic CI evidence: https://github.com/BerriAI/litellm/actions/runs/31763090709 failed on the same three tests in the original run and again on a full rerun, on a PR touching only scripts/pre_commit_lint.sh and its test
Red-green on the regression pair, before at 86f2f16 (staging tip conftest plus only the new test file):
After at a36ba05:
Full tests/test_litellm/proxy sweep on the same machine went from 7 failed, 7296 passed at the base to 4 failed, 7299 passed with the fix. The three recovered tests are exactly the three CI victims. The residual failures also fail identically at the base and are local environment artifacts: a machine-local sso settings failure, two tests needing the optional detect_secrets package, and one test reading a PROXY_BASE_URL left in the local .env
Type
✅ Test
Caveats (if any)
Final Attestation