test: add six ruff rules that catch tests which cannot fail - #37709
Conversation
`assert False` inside a `try:` raises AssertionError, which the `except Exception` right below it catches, so several tests reported green no matter what the code did. `pytest.fail` raises Failed, a BaseException, and escapes. A bare `a == b` statement is evaluated and discarded. Nine of those sat in tests, and one was comparing against a model name the router never produces. Selects B011, B015, B018, PT015, PLR0133 and PLW0127 in ruff-tests.toml alongside F821, with all 50 existing violations fixed, so no budget file or ratchet is needed. CI already runs this config over tests/.
Greptile SummaryThis PR strengthens test reliability by enabling six Ruff checks for ineffective test statements and repairing the existing violations.
Confidence Score: 5/5The PR appears safe to merge, with the changed tests becoming stricter and no concrete regressions identified. The lint configuration is wired to the existing test-lint command, swallowed failure paths now escape correctly, and the newly active assertions match the exercised production behavior.
|
| Filename | Overview |
|---|---|
| ruff-tests.toml | Enables six additional rules targeting ineffective assertions, comparisons, expressions, and self-assignments in tests. |
| tests/llm_translation/test_containers_api.py | Uses pytest.fail so missing expected API errors can no longer be swallowed by the surrounding broad exception handlers. |
| tests/local_testing/test_router_pattern_matching.py | Parses the outgoing request and adds active assertions for the routed model and transformed message payload. |
| tests/test_litellm/proxy/db/mcp_server/test_db.py | Replaces a constant placeholder assertion with parametrized coverage of team MCP-server lookup behavior and database-call arguments. |
| tests/test_team.py | Restores an active assertion for the updated team membership count using the post-update team snapshot. |
| tests/local_testing/test_custom_llm.py | Restores assertions that verify custom image-generation credentials and optional parameters are forwarded. |
| tests/test_litellm/passthrough/test_passthrough_main.py | Restores validation of the URL supplied to the passthrough HTTP request. |
| tests/local_testing/test_secret_detect_hook.py | Restores validation that detected secrets are redacted from callback data. |
Reviews (1): Last reviewed commit: "test: add six ruff rules that catch test..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
tin-berri
left a comment
There was a problem hiding this comment.
Adds 6 ruff rules catching tests that structurally cannot fail (assert False inside try/except swallowing AssertionError, bare == comparisons with no assert) and fixes all 50 existing violations by hand. The proof here is unusually strong — 4 real mutations against actual production bugs (MCP team-server-scope grant broken, custom LLM api_key silently dropped, wildcard routing not substituting, container-file-not-found error swallowed hitting the live OpenAI API) each show the OLD test staying green and the NEW test catching it. Confirms the 66 pre-existing failures across touched files are identical before/after (env-credential-gated, not introduced by this PR). This is exactly the kind of test-quality PR that's worth taking seriously since it found real latent bugs while fixing itself. CI green.
TLDR
Problem this solves:
assert Falsein atry:is caught by its ownexcepta == bstatements evaluate and throw the result awaytests/, several unable to ever failHow it solves it:
ruff-tests.toml, already wired to CIassert Falseaspytest.fail, which escapesexcept Exceptionasserton 9 dead comparisonsTrue == True; now it tests its moduleUser Flow
Before: a proxy admin scopes MCP servers to a team, the gateway stops honoring that scope, and no test objects
True == Trueor hide their failure inside their ownexcept ExceptionAfter: both regressions are caught before merge
Relevant issues
Linear ticket
Pre-Submission checklist
Screenshots / Proof of Fix
This PR changes lint config and tests, so there is no proxy route to curl. The proof is four mutations: break a behavior a test exists to police, and show the old test does not notice while the new one does. Every command is identical on both sides; only the
tests/tree differs.The four mutations, applied one at a time and reverted after each run:
container_file_contenthits the real OpenAI containers API with a live key: it creates a container, asks for a file that does not exist, and deletes the container.Before (4af59d7)
Team MCP server grants stop working, test still green
mcp_team_servers, then runCustom provider stops receiving the caller's api_key, test still green
custom_llm_api_key, then runWildcard routing stops substituting the model, test still green
pattern_wildcard, then runContainer file errors get swallowed, test still green
container_file_content, then run against the live OpenAI APIAfter (634131b)
Team MCP server grants stop working, test now fails
mcp_team_serversand run the same command:Custom provider stops receiving the caller's api_key, test now fails
custom_llm_api_keyand run the same command:Wildcard routing stops substituting the model, test now fails
pattern_wildcardand run the same command:Container file errors get swallowed, test now fails
container_file_contentand run the same command against the live OpenAI API:The gate is clean and would catch the next one
Touched files are unchanged in pass/fail
4af59d7c6e, on absent Gemini, Bedrock, Azure and Databricks credentials.commover the two FAILED lists reports no id that fails only after this PR.Type
🧹 Refactoring
🚄 Infrastructure
✅ Test
Caveats (if any)
ruff-tests.tomland F821test_router_pattern_match_e2ecompared against a model it never routes toFinal Attestation