mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-07 08:26:10 +00:00
* test(lint): ban blind pytest.raises(Exception) with ruff B017 A bare pytest.raises(Exception) accepts whatever the body throws. The TypeError a refactor introduces satisfies it exactly as well as the rejection the test was written for, so the crash reads as a pass and the test never goes red. All 111 existing sites are narrowed here. A runtime probe recorded the concrete exception each one actually catches, and each site now names that type. Where the code under test genuinely raises a bare Exception, the site pins a stable slice of the message with match= instead. Two sites tell on themselves. The shared responses-API cancel test raises "custom_llm_provider is required but passed as None" rather than talking to a provider at all, because cancel_responses takes a provider, not a model. And test_bedrock_guardrails_with_streaming was the only test in its file still passing without AWS credentials, because the NoCredentialsError boto3 raised long before the guardrail ran satisfied the blind raises. * fix(test): widen the openai batch-dispatch assertion to OpenAIError The narrowed NotFoundError only holds where OPENAI_API_KEY is set. Without one the SDK raises OpenAIError while building the client, long before any 404, so CI went red. OpenAIError covers both and still rejects a TypeError from a refactor.
27 lines
1.5 KiB
TOML
27 lines
1.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
|
|
#
|
|
# 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 = ["F821", "B011", "B015", "B017", "B018", "PT015", "PLR0133", "PLW0127"]
|