Skip to content

QA-PY-007 — pytest.raises without match ​

← Back to the rule catalog

Generated from the rule registry. Get the same detail from the CLI with mjolnir explain QA-PY-007.

FieldValue
Severitywarning
Confidencemedium
Tierquarantine
Measured FP ratenot yet measured
Evidence levelE1
QA impactFalse-green risk (FALSE-GREEN)
False-positive risk (author estimate)medium
Autofix availableno
Languagespython
Frameworkspytest
Detection strategyLEXICAL
Introduced inv0.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):

RepoOccurrences
apache-airflow1332
getsentry-sentry1350
pallets-click1
psf-requests42
pyca-cryptography1567
pytest-dev-pytest11
reflex-dev-reflex235
SeleniumHQ-selenium2
streamlit-streamlit490

Released under the MIT License.