test(s3): stop the logger tests leaking s3_callback_params on failure - #37831
Conversation
Ten tests set litellm.s3_callback_params by hand. Four of them reset it to None on the last line of the test body, which only runs when the test passes; the other six wrap the body in try/finally to put the old value back. Raising inside test_s3_verify_false_handling on the current file leaves the whole callback config, bucket, endpoint and keys, set in the process for whatever runs next. monkeypatch.setattr covers both shapes and restores on failure, so the 28 TQ005 violations and the try/finally scaffolding come out together. 51 tests pass, and the wider tests/test_litellm/integrations tree is unchanged. The five TQ002 mock-echo tests in this file are left alone; those need a judgement about what S3 logging should assert, not a mechanical sweep.
Greptile SummaryThe PR replaces manual mutation and cleanup of
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| tests/test_litellm/integrations/test_s3_v2.py | Replaces direct global assignments and manual cleanup with automatically restored monkeypatch state without changing test assertions or production behavior. |
| test-quality-budget.json | Reduces the TQ005 allowance from 2832 to 2804 to account for the eliminated test-quality violations. |
Reviews (2): Last reviewed commit: "test(s3): stop the logger tests leaking ..." | Re-trigger Greptile
|
|
||
| @pytest.mark.asyncio | ||
| async def test_s3_verify_false_creates_httpx_client_with_verify_false(): | ||
| async def test_s3_verify_false_creates_httpx_client_with_verify_false(monkeypatch: pytest.MonkeyPatch): |
There was a problem hiding this comment.
Changed lines exceed length limit
The changed test declaration exceeds the repository's 120-character Python line limit, and the same pattern appears in several other changed setup and assertion lines, making this test harder to scan and maintain.
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
The longest line this PR adds is 104 characters and the limit here is 120, so I read that one as a false positive |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…itellm_s3_callback_params_leak # Conflicts: # test-quality-budget.json
TLDR
Problem this solves:
litellm.s3_callback_paramsby handHow it solves it:
monkeypatch.setattrrestores on failure tooUser Flow
No end-user behavior changes. A proxy admin logging spend to S3 gets the same
objects written the same way; this is the test file around that logger, not the
logger
Relevant issues
Linear ticket
Pre-Submission checklist
Screenshots / Proof of Fix
Shared setup: clear the global, run one test with one line forced to fail, read
the global back in the same interpreter. A passing run is clean on both sides,
so the forced failure is the only state where they differ.
Before (ff02d5c)
raise AssertionError("forced")above the first assert oftest_s3_verify_false_handling, then run the command aboveuv run python scripts/check_test_quality.py tests/test_litellm/integrations/test_s3_v2.py | grep -oE "TQ00[0-9]" | sort | uniq -cAfter (073fe21)
uv run python scripts/check_test_quality.py tests/test_litellm/integrations/test_s3_v2.py | grep -oE "TQ00[0-9]" | sort | uniq -cuv run pytest tests/test_litellm/integrations/ -q -p no:randomly -n 4Type
🐛 Bug Fix
✅ Test
Caveats (if any)
test-quality-budget.json, as do test: drop the cwd-relative sys.path.insert calls from the test suite #37802, test: unwind environment writes in tests/test_litellm with monkeypatch #37806, test(cost-calc): stop 182 global writes leaking out of the cost-calc suites #37815, test(mcp): retire the last file of the dead tests/litellm mirror #37824, test(callbacks): unwind the callbacks global the policy engine and realtime tests scaffold around #37826 and test(guardrails): stop the onyx and prompt security tests leaking env vars on failure #37828Final Attestation