pytest.raises is called as a statement, so it checks nothing
What it finds
pytest.raises(ValueError) on a line of its own: called with only the exception type, pytest.raises returns a context manager and checks nothing until it is used in a with statement. As a statement it does nothing, and the test passes whether or not the code raises.
Calls that also pass the function to call, the older form that checks at once, are left alone.
From the rule's source, raises_context_unused.rs.
import pytest def test_parse(parse): pytest.raises(ValueError)tx0 reports: used as a statement, this checks nothing parse("x") pytest.raises(ValueError, parse, "x") with pytest.raises(ValueError): parse("y") Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/python:raises-context-unused" = "off"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-context-unused] reason="..."tx0 explain tx0/python:raises-context-unused shows the same in the terminal. Found a false positive? Report it.