A test expects Exception or BaseException to be raised, which any error satisfies

tx0/python:raises-broad-exceptionrecommendedwarningreliability/error-handlingdepth fastbug

What it finds

pytest.raises(Exception) and self.assertRaises(Exception) pass for a typo, a TypeError from a wrong call or any other failure, so the test does not show that the intended error happened. A specific class, or match= on the message, does. Calls that give match are left alone.

From the rule's source, raises_broad_exception.rs.

Example from the rule's tests
import pytest def test_it():    with pytest.raises(Exception):tx0 reports: expecting Exception lets any error pass        run()    with pytest.raises(Exception, match="bad input"):        run()    with pytest.raises(ValueError):        run()
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/python:raises-broad-exception" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

# tx0: ignore[tx0/python:raises-broad-exception] reason="..."

tx0 explain tx0/python:raises-broad-exception shows the same in the terminal. Found a false positive? Report it.