mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-07 08:26:10 +00:00
A name bound twice keeps only the second binding. In `tests/` that is nearly always a repeated import, harmless but misleading, and the same rule is what catches the cases that are not harmless: a local that shadows an import the module still calls, and a second `def test_x` that quietly replaces the first. 311 of the 344 sites were repeated imports and came out with ruff's own fix. The remaining 33 needed a decision. Four modules imported a name they never used because a local definition below already shadowed it. Two comprehensions bound `call` over `unittest.mock.call`, which those modules import and use. One test rebound the two module handles its nested reload closure had captured. One class attribute shadowed an unused `status` import. The load-test fixtures move to a conftest, which is how pytest is meant to share them, so the test module no longer imports three fixture names it never calls. The nine `prisma_client` parameters keep a narrow `noqa`: pytest resolves that fixture by name before the body runs, so the parameter never shadows anything.
39 lines
2.5 KiB
TOML
39 lines
2.5 KiB
TOML
# Lint config for the test tree, which ruff.toml excludes from `ruff check`.
|
|
#
|
|
# Every rule here catches a test that cannot fail. Rules land one at a time, each
|
|
# with its existing violations already fixed, so this list never needs a budget
|
|
# file or a ratchet.
|
|
#
|
|
# F821 a name that does not exist raises NameError, and a test body wrapped in
|
|
# `except Exception: pass` swallows that NameError and reports green
|
|
# B011 `assert False` inside `try:` raises AssertionError, which the `except
|
|
# Exception` below it catches. `pytest.fail` raises BaseException and escapes
|
|
# PT015 same site as B011, from the pytest ruleset
|
|
# B015 a bare `a == b` statement is evaluated and thrown away; the missing `assert`
|
|
# means the test checks nothing
|
|
# B018 a bare attribute access or literal, usually a call missing its parens
|
|
# PLW0127 `x = x` self-assignment, dead code that reads like a narrowing or a fixup
|
|
# PLR0133 comparison of two constants, e.g. `assert True == True`
|
|
# B017 `pytest.raises(Exception)` accepts the TypeError a refactor introduced just as
|
|
# readily as the rejection under test, so a crash reads as a pass. Narrow to the
|
|
# real type, or add `match=` where the code genuinely raises a bare Exception
|
|
# PT012 a `pytest.raises` block that runs on past the raising call. Everything after
|
|
# that call is dead, so an `assert` sitting there is never checked. Keep the
|
|
# block to the call itself and put the assertions below it
|
|
# PT011 `pytest.raises(Exception)` / `(ValueError)` / `(OSError)` with no `match=`. The
|
|
# block passes on any error that broad, so the TypeError a refactor introduced
|
|
# reads as the rejection under test. Pin the message the code actually raises
|
|
# PT014 the same `parametrize` case listed twice. The copy re-runs an assertion that
|
|
# already passed and adds no coverage, and it usually marks a case someone meant
|
|
# to vary and forgot to edit
|
|
# F811 a name bound twice where the first binding was never used. Mostly a repeated
|
|
# import, but the same rule is what catches a second `def test_x` silently
|
|
# replacing the first, and a local that shadows an import the module still calls
|
|
#
|
|
# No target-version here on purpose: it resolves from requires-python (>=3.10), so
|
|
# 3.11-only builtins like BaseExceptionGroup are correctly flagged in a tree that
|
|
# still has to run on 3.10.
|
|
|
|
line-length = 120
|
|
|
|
lint.select = ["F811", "F821", "B011", "B015", "B017", "B018", "PT011", "PT012", "PT014", "PT015", "PLR0133", "PLW0127"]
|