Repository navigation
test: isolate model cost maps in runtime registration tests - #47559
mateo-berri merged 4 commits into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@litereview code-review |
✅ code-review5/5 · Ready for human reviewScope: full · Full PR review. No correctness findings. The PR changes only test isolation in Checks and execution details
Traced the path from Teardown order also works. Defect-sensitive oracle: with All 712 tests in
View review · Reviewed |
[Low impact] The PR appears safe to merge with no new actionable findings SummaryThe PR restores model catalogs between unit tests and adds checks that registration writes do not leak into later tests
Reviews (6) · Last reviewed commit: "test: snapshot litellm globals before sc..." · Reviewed by Greptile |
|
@litereview code-review |
|
@litereview code-review |
|
@litereview code-review |
1 similar comment
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 43fd294. Configure here.
mateo-berri
left a comment
There was a problem hiding this comment.
LGTM. Thanks for the contribution!
TLDR
Problem this solves:
How it solves it:
local_model_cost_mapThe tests save
litellm.model_costby reference, mutate it throughregister_model, then restore the already-mutated dictionary, so disabled GPT-4o function calling or custom prices leak into later tests on the same xdist worker. The shared conftest had the same by-reference restore, and nothing restoredlitellm.models_by_provider, whichregister_modelalso writesA new autouse fixture in the
tests/unitconftest snapshotslitellm.model_cost,litellm.models_by_providerand everylitellm.*_modelsset before each test and puts their contents back in place after it, so references other modules hold stay valid. A canary pair intest_conftest_isolation.pyregisters a model and overrides a price in one test, then checks the next test sees neither. Production code is unchangedUser Flow
Before: a contributor whose PR touches unrelated code sees the required
unit passedcheck go red on a test they never touchedunit passedcheck fails withAssertionError: Direct model gpt-4o should return True, even after pytest's rerunsAfter: the same PR gets a green
unit passedcheck whatever order the tests run inunit passedcheck goes green with no rerunRelevant issues
Observed in #38908 (failed root job)
#47135 includes a fix for the override test alongside several unrelated flakes. This PR isolates the model-cost fix and also covers the adjacent request-scoped registration test
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or moreDelays 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
The client is pytest, run the way the required
rootunit shard runs it:LITELLM_LOCAL_MODEL_COST_MAP=True, under xdist, with CI'scidependency group installed. Both trees were bootstrapped withmake bootstrap. Before ran at the merge base and After at this PR's tip, with the same commandsBefore (dd20bb0)
CI worker replay
Loadscope order, one worker
Steps and output
TestProxyFunctionCallingclass, as they did on gw3Minimal pair
Steps and output
Provider model list
Steps and output
Catalog restore canary
Steps and output
Copy this PR's
tests/unit/test_conftest_isolation.pyinto the merge base tree, leaving the conftest as it is thereRun the canary pair
After (43fd294)
CI worker replay
Loadscope order, one worker
Steps and output
Minimal pair
Steps and output
Provider model list
Steps and output
Catalog restore canary
Steps and output
Notes from the run
make bootstraplacks CI'scigroup, so it was addedType
✅ Test
Caveats (if any)
Low
--dist loadrun can split themtests/unitleaks todaylocal_model_cost_mapon both reapply tests is now redundantFinal Attestation
Bugbot summary