test(lint): fix PT011/PT012 introduced by #37736, blocking lint on every PR - #37870
Closed
tin-berri wants to merge 1 commit into
Closed
test(lint): fix PT011/PT012 introduced by #37736, blocking lint on every PR#37870tin-berri wants to merge 1 commit into
tin-berri wants to merge 1 commit into
Conversation
Two whole-tree test lints are red on litellm_internal_staging, which blocks the lint job on every PR into it. test_user_api_key_auth.py used pytest.raises(Exception) with no match=. B017 forbids that (enforced since #37731): any Exception subtype, including one from an unrelated regression, satisfies the assert and reads as a pass. Narrowed with match=r"(?i)budget", which preserves the original `assert "budget" in str(exc.value).lower()` it replaces. test_unit_test_max_model_budget_limiter.py wrapped an if/else with two different awaited calls inside pytest.raises(). PT012 forbids that (enforced since #37748): the block must hold a single simple statement, so a coroutine built in the wrong branch cannot silently never run. The coroutine is now built outside the block and awaited inside it. Both violations landed in #37736, one day before ruff-tests.toml began enforcing these rules whole-tree, so no delta-vs-base gate caught them. Verified: `ruff check --config ruff-tests.toml tests` is clean, both tests pass, and each still fails under an injected regression.
Contributor
Greptile SummaryThis PR fixes two test lint violations without changing production behavior.
Confidence Score: 5/5The PR appears safe to merge because both changes preserve the existing test behavior while satisfying the lint rules. Both limiter calls are native async methods whose bodies still execute inside
|
| Filename | Overview |
|---|---|
| tests/proxy_unit_tests/test_unit_test_max_model_budget_limiter.py | Coroutine selection now occurs before pytest.raises, while execution and exception capture remain inside it for both parametrized branches. |
| tests/proxy_unit_tests/test_user_api_key_auth.py | The exception assertion is expressed through an equivalent case-insensitive regex while retaining the user-ID check. |
Reviews (1): Last reviewed commit: "test(lint): fix PT011/PT012 in tests int..." | Re-trigger Greptile
5 tasks
tin-berri
enabled auto-merge (squash)
August 21, 2026 22:17
yucheng-berri
approved these changes
Aug 21, 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
ruff check --config ruff-tests.toml testsis red onlitellm_internal_staging, which blocks the lint job for every open PR into it (including unrelated ones — it's a whole-tree check, not delta-vs-base).Both violations landed in #37736, merged the day before B017/PT012 started being enforced whole-tree in #37731/#37748, so no delta-vs-base gate caught them at the time.
Changes
tests/proxy_unit_tests/test_user_api_key_auth.py:pytest.raises(Exception)with nomatch=(B017) — anyExceptionsubtype, including one from an unrelated regression, satisfies the assert and reads as a pass. Narrowed tomatch=r"(?i)budget", which preserves theassert "budget" in str(exc.value).lower()it replaces.tests/proxy_unit_tests/test_unit_test_max_model_budget_limiter.py: anif/elseselecting between two different awaited calls, both insidepytest.raises()(PT012) — the block must hold a single simple statement so a coroutine built in the wrong branch can't silently never run. Coroutine is now built outside the block and awaited inside it.Verification
uv run --no-sync ruff check --config ruff-tests.toml tests: clean.Pre-Submission checklist