QA-PY-007 — pytest.raises without match
Generated from the rule registry. Get the same detail from the CLI with
mjolnir explain QA-PY-007.
| Field | Value |
|---|---|
| Severity | warning |
| Confidence | medium |
| Tier | quarantine |
| Measured FP rate | not yet measured |
| Evidence level | E1 |
| QA impact | False-green risk (FALSE-GREEN) |
| False-positive risk (author estimate) | medium |
| Autofix available | no |
| Languages | python |
| Frameworks | pytest |
| Detection strategy | LEXICAL |
| Introduced in | v0.3.0 |
Why this fails in production
Without match=, any exception of that type anywhere in the block passes — including one raised by an unrelated bug before the code under test even runs.
What gets flagged (real detector output)
`pytest.raises` without a `match=` pattern.Example from this rule's own must-fire fixture: tests/fixtures/QA-PY-007/must-fire/multi-statement-block.py
The fix
Add match="expected message fragment" to pin the failure to the intended cause.
Confirmed NOT to fire on the corresponding clean pattern
Verified against tests/fixtures/QA-PY-007/must-not-fire/excinfo-assertion.py — a legitimate, similar-looking pattern this rule correctly leaves alone.
Corpus-measured false-positive risk
Real occurrence counts from npm run corpus:audit against actively-maintained OSS repos — reproduce yourself, don't just trust this table (see the false-positive audit):
| Repo | Occurrences |
|---|---|
| apache-airflow | 1332 |
| getsentry-sentry | 1350 |
| pallets-click | 1 |
| psf-requests | 42 |
| pyca-cryptography | 1567 |
| pytest-dev-pytest | 11 |
| reflex-dev-reflex | 235 |
| SeleniumHQ-selenium | 2 |
| streamlit-streamlit | 490 |