A test expects Exception or BaseException to be raised, which any error satisfies
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.
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() 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:
[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.