Skip to content

PT010 should be updated for pytest 8.4.0 #18653

@dscorbett

Description

@dscorbett

Summary

The documentation for pytest-raises-without-exception (PT010) says:

pytest.raises expects to receive an expected exception as its first argument. If omitted, the pytest.raises call will fail at runtime.

As of pytest 8.4.0 (released June 2, 2025) it is also sufficient to pass the keyword argument match or check. The rule should recognize those arguments too.

$ cat >pt010.py <<'# EOF'
import pytest
with pytest.raises(match=r"!+"):
    raise RuntimeError("!!!")
with pytest.raises(check=lambda _e: True):
    raise RuntimeError("...")
# EOF

$ python pt010.py; echo $?
0

$ ruff --isolated check pt010.py --select PT010 --output-format concise -q
pt010.py:2:6: PT010 Set the expected exception in `pytest.raises()`
pt010.py:4:6: PT010 Set the expected exception in `pytest.raises()`

Version

ruff 0.11.13 (5faf72a 2025-06-05)

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentationhelp wantedContributions especially welcomeruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions