test(bedrock): let monkeypatch own bedrock_request_metadata_fields - #37840
Merged
yuneng-berri merged 1 commit intoAug 22, 2026
Merged
Conversation
Twenty tests in test_request_metadata.py assigned the global directly and leaned on an autouse fixture to put it back afterwards. monkeypatch.setattr does both jobs at the point of use, so each test now says what it sets and the fixture that existed only to undo them goes away.
Contributor
Greptile SummaryThis test-only refactor moves cleanup of
Confidence Score: 5/5The PR appears safe to merge because it preserves test behavior while localizing and automating global-state cleanup. Every changed mutation is restored by pytest's monkeypatch lifecycle, assertions and parameterization remain unchanged, and the quality-budget reduction matches the eliminated violations.
|
| Filename | Overview |
|---|---|
| tests/test_litellm/llms/bedrock/test_request_metadata.py | All global-setting mutations are now monkeypatch-owned and automatically restored, with test behavior and coverage unchanged. |
| test-quality-budget.json | Reduces the TQ005 ceiling by 22, matching the 22 direct global assignments eliminated from the test file. |
Reviews (1): Last reviewed commit: "test(bedrock): let monkeypatch own bedro..." | 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:
litellm.bedrock_request_metadata_fieldsdirectlyHow 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 61 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 fixture it removes already restored the global, so the run reads "restored" on both sides. That is the point. The bookkeeping was correct and sitting fifty lines 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 global back in the same interpreter, then count what the quality rules see in it.
Before (ff02d5c)
After (2ac787e)
uv run python scripts/test_quality_gate.py --base origin/litellm_internal_stagingType
🧹 Refactoring
✅ Test
Caveats (if any)
sys.path.insert, left for its own changeFinal Attestation