Skip to content

test(lint): fix PT011/PT012 introduced by #37736, blocking lint on every PR - #37870

Closed
tin-berri wants to merge 1 commit into
litellm_internal_stagingfrom
litellm_staging_lint_debt_pt011_pt012
Closed

test(lint): fix PT011/PT012 introduced by #37736, blocking lint on every PR#37870
tin-berri wants to merge 1 commit into
litellm_internal_stagingfrom
litellm_staging_lint_debt_pt011_pt012

Conversation

@tin-berri

Copy link
Copy Markdown
Contributor

TLDR

ruff check --config ruff-tests.toml tests is red on litellm_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 no match= (B017) — any Exception subtype, including one from an unrelated regression, satisfies the assert and reads as a pass. Narrowed to match=r"(?i)budget", which preserves the assert "budget" in str(exc.value).lower() it replaces.
  • tests/proxy_unit_tests/test_unit_test_max_model_budget_limiter.py: an if/else selecting between two different awaited calls, both inside pytest.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.
  • Both tests pass as edited.
  • Mutation-checked each: injecting an unrelated exception / dropping the pre-seeded spend still fails the test, confirming the restructuring didn't weaken what's being asserted.

Pre-Submission checklist

  • I have added meaningful tests (N/A — test-only lint fix, no behavior change)
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem

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.
@greptile-apps

greptile-apps Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes two test lint violations without changing production behavior.

  • Restructures a parametrized budget-limiter test so pytest.raises contains one awaited statement.
  • Moves the existing case-insensitive budget-message assertion into pytest.raises(match=...).

Confidence Score: 5/5

The 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 pytest.raises, and the revised exception match preserves the removed case-insensitive budget substring assertion.

Important Files Changed

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

@tin-berri tin-berri closed this Aug 21, 2026
auto-merge was automatically disabled August 21, 2026 22:26

Pull request was closed

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.

2 participants