Skip to content

Commit

Permalink
Better wording for PT011
Browse files Browse the repository at this point in the history
Closes #150
  • Loading branch information
m-burst committed Nov 5, 2021
1 parent 2fa5ac0 commit a7a4e3a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Currently the following errors are reported:
| [PT008] | use return_value= instead of patching with lambda |
| [PT009] | use a regular assert instead of unittest-style '{assertion}' |
| [PT010] | set the expected exception in pytest.raises() |
| [PT011] | set the match parameter in pytest.raises({exception}) <br> (configurable by `pytest-raises-require-match-for`) |
| [PT011] | pytest.raises({exception}) is too broad, set the match parameter or use a more specific exception <br> (configurable by `pytest-raises-require-match-for`) |
| [PT012] | pytest.raises() block should contain a single simple statement |
| [PT013] | found incorrect import of pytest, use simple 'import pytest' instead |
| [PT014] | found duplicate test cases {indexes} in @pytest.mark.parametrize |
Expand Down Expand Up @@ -82,7 +82,8 @@ MIT

**Unreleased**

...
* better wording for [PT011]
* support Python 3.10

**1.5.0 - 2021-06-18**

Expand Down
2 changes: 1 addition & 1 deletion docs/rules/PT011.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PT011

`set the match parameter in pytest.raises({exception})`
`pytest.raises({exception}) is too broad, set the match parameter or use a more specific exception`

## Configuration

Expand Down
7 changes: 5 additions & 2 deletions flake8_pytest_style/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ class RaisesWithoutException(Error):
message = 'set the expected exception in pytest.raises()'


class RaisesWithoutMatch(Error):
class RaisesTooBroad(Error):
code = 'PT011'
message = 'set the match parameter in pytest.raises({exception})'
message = (
'pytest.raises({exception}) is too broad,'
' set the match parameter or use a more specific exception'
)


class RaisesWithMultipleStatements(Error):
Expand Down
4 changes: 2 additions & 2 deletions flake8_pytest_style/visitors/raises.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from flake8_pytest_style.config import Config
from flake8_pytest_style.errors import (
AssertInExcept,
RaisesTooBroad,
RaisesWithMultipleStatements,
RaisesWithoutException,
RaisesWithoutMatch,
)
from flake8_pytest_style.utils import (
get_qualname,
Expand Down Expand Up @@ -41,7 +41,7 @@ def _check_raises_call(self, node: ast.Call) -> None:
return
match = args.get_argument('match')
if match is None or is_none(match) or is_empty_string(match):
self.error_from_node(RaisesWithoutMatch, node, exception=exception_name)
self.error_from_node(RaisesTooBroad, node, exception=exception_name)

def _check_raises_with(self, node: ast.With) -> None:
"""Checks for PT012."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from flake8_plugin_utils import assert_error, assert_not_error

from flake8_pytest_style.config import DEFAULT_CONFIG
from flake8_pytest_style.errors import RaisesWithoutMatch
from flake8_pytest_style.errors import RaisesTooBroad
from flake8_pytest_style.visitors import RaisesVisitor


Expand Down Expand Up @@ -40,7 +40,7 @@ def test_something():
assert_error(
RaisesVisitor,
code,
RaisesWithoutMatch,
RaisesTooBroad,
config=DEFAULT_CONFIG,
exception=exception,
)
Expand All @@ -58,7 +58,7 @@ def test_something():
assert_error(
RaisesVisitor,
code,
RaisesWithoutMatch,
RaisesTooBroad,
config=DEFAULT_CONFIG,
exception='ValueError',
)

0 comments on commit a7a4e3a

Please sign in to comment.