test(audit-logs): let monkeypatch own the audit log and s3 callback globals - #37842
Merged
yuneng-berri merged 1 commit intoAug 22, 2026
Merged
Conversation
…lobals Fifteen tests assigned litellm.audit_log_callbacks, s3_callback_params or s3_audit_callback_params directly and leaned on two autouse fixtures to put them back. monkeypatch.setattr does that at the point of use, so each test now says what it sets, including the one that swaps the value mid-test to prove the cache does not serve the stale params. The fixtures keep only the work monkeypatch cannot do: the per-test empty callback list, and clearing the logger and audit caches around each test.
Contributor
Greptile SummaryThis test-only refactor delegates restoration of audit-log and S3 callback globals to pytest's monkeypatch fixture while retaining explicit cache cleanup
Confidence Score: 5/5The PR appears safe to merge because the test state remains isolated and the quality-budget reduction matches the removed violations Monkeypatch restores each modified global after dependent fixtures finish, while explicit teardown leaves both logger caches empty and preserves the previous isolation behavior
|
| Filename | Overview |
|---|---|
| tests/test_litellm/proxy/management_helpers/test_audit_log_callbacks.py | Replaces direct callback-global mutation with monkeypatch-managed state without changing test assertions or leaving stale caches |
| test-quality-budget.json | Lowers the TQ005 ceiling by 22 to match the direct global assignments removed from the test file |
Reviews (1): Last reviewed commit: "test(audit-logs): let monkeypatch own th..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
ryan-crabbe-berri
approved these changes
Aug 22, 2026
yucheng-berri
approved these changes
Aug 22, 2026
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:
monkeypatch.setattrsets and restores at the point of useUser Flow
This one is test-only scaffolding with no user-visible behavior, so there is no before and after flow to walk. The tests assert the same things on the same code, and the same 27 pass either way
Relevant issues
Linear ticket
Pre-Submission checklist
uv run pytest tests/test_litellm/<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 more@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
To be plain about what this does and does not prove: the autouse fixtures already restored these globals, so the run reads "restored" on both sides. That is the point. The bookkeeping was correct and sitting far from the code it covered, and
monkeypatchdoes the same job where the value is set. What changes is the count the quality rules see.Shared setup: run the file, read the globals back in the same interpreter, then count what the quality rules see in it.
Before (ff02d5c)
After (52832d9)
uv run python scripts/test_quality_gate.py --base origin/litellm_internal_stagingType
🧹 Refactoring
✅ Test
Caveats (if any)
Final Attestation