Skip to content

test(s3): stop the logger tests leaking s3_callback_params on failure - #37831

Merged
yuneng-berri merged 2 commits into
litellm_internal_stagingfrom
litellm_s3_callback_params_leak
Aug 22, 2026
Merged

test(s3): stop the logger tests leaking s3_callback_params on failure#37831
yuneng-berri merged 2 commits into
litellm_internal_stagingfrom
litellm_s3_callback_params_leak

Conversation

@yuneng-berri

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Ten tests set litellm.s3_callback_params by hand
  • Four reset it on a line that only runs when they pass
  • A failure leaves bucket, endpoint and keys set

How it solves it:

  • monkeypatch.setattr restores on failure too
  • The six try/finally blocks come out with it

User 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

  • I have added meaningful tests
  • The handful of test files covering my change pass locally
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review

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.

uv run python -c '
import litellm, pytest
litellm.s3_callback_params = None
pytest.main(["tests/test_litellm/integrations/test_s3_v2.py::test_s3_verify_false_handling", "-q", "-p", "no:randomly"])
print("litellm.s3_callback_params after the run:", litellm.s3_callback_params)
'

Before (ff02d5c)

  1. Add raise AssertionError("forced") above the first assert of
    test_s3_verify_false_handling, then run the command above
litellm.s3_callback_params after the run: {'s3_bucket_name': 'test-bucket', 's3_endpoint_url': 'https://localhost:443', 's3_aws_access_key_id': 'minioadmin', 's3_aws_secret_access_key': 'minioadmin', 's3_region_name': 'us-east-1', 's3_verify': False, 's3_use_ssl': False}
  1. uv run python scripts/check_test_quality.py tests/test_litellm/integrations/test_s3_v2.py | grep -oE "TQ00[0-9]" | sort | uniq -c
   5 TQ002
  28 TQ005

After (073fe21)

  1. Same injection, same command
litellm.s3_callback_params after the run: None
  1. uv run python scripts/check_test_quality.py tests/test_litellm/integrations/test_s3_v2.py | grep -oE "TQ00[0-9]" | sort | uniq -c
   5 TQ002
  1. uv run pytest tests/test_litellm/integrations/ -q -p no:randomly -n 4
2823 passed, 3 skipped, 153 warnings, 2 subtests passed in 24.62s

Type

🐛 Bug Fix

✅ Test

Caveats (if any)

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

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-apps

greptile-apps Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR replaces manual mutation and cleanup of litellm.s3_callback_params in S3 logger tests with pytest's automatically restored monkeypatch fixture.

  • Removes failure-sensitive cleanup scaffolding from ten S3 tests.
  • Lowers the TQ005 test-quality budget to reflect the removed direct global mutations.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

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):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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!

@yuneng-berri

Copy link
Copy Markdown
Contributor Author

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

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@yuneng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

…itellm_s3_callback_params_leak

# Conflicts:
#	test-quality-budget.json
@yuneng-berri
yuneng-berri merged commit 092d977 into litellm_internal_staging Aug 22, 2026
68 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_s3_callback_params_leak branch August 22, 2026 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants