-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
pytest-raises-too-broad (PT011)
to flag pytest.raises
call wi…
…th keyword `expected_exception` (#14298) ## Summary <!-- What's the purpose of the change? What does it do, and why? --> `pytest-raises-too-broad (PT011)` should be raised when `expected_exception` is provided as a keyword argument. ```python def test_foo(): with pytest.raises(ValueError): # raises PT011 raise ValueError("Can't divide 1 by 0") # This is minor but a valid pytest.raises call with pytest.raises(expected_exception=ValueError): # doesn't raise PT011 but should raise ValueError("Can't divide 1 by 0") ``` `pytest.raises` doc: https://docs.pytest.org/en/8.3.x/reference/reference.html#pytest.raises ## Test Plan <!-- How was it tested? --> Unit tests Signed-off-by: harupy <[email protected]>
- Loading branch information
Showing
6 changed files
with
88 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 10 additions & 12 deletions
22
...st_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT011_glob_prefix.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,20 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs | ||
--- | ||
PT011.py:24:24: PT011 `pytest.raises(pickle.PicklingError)` is too broad, set the `match` parameter or use a more specific exception | ||
PT011.py:27:24: PT011 `pytest.raises(pickle.PicklingError)` is too broad, set the `match` parameter or use a more specific exception | ||
| | ||
22 | raise ValueError("Can't divide 1 by 0") | ||
23 | | ||
24 | with pytest.raises(PicklingError): | ||
25 | raise ValueError("Can't divide 1 by 0") | ||
26 | | ||
27 | with pytest.raises(PicklingError): | ||
| ^^^^^^^^^^^^^ PT011 | ||
25 | raise PicklingError("Can't pickle") | ||
28 | raise PicklingError("Can't pickle") | ||
| | ||
|
||
PT011.py:27:24: PT011 `pytest.raises(pickle.UnpicklingError)` is too broad, set the `match` parameter or use a more specific exception | ||
PT011.py:30:24: PT011 `pytest.raises(pickle.UnpicklingError)` is too broad, set the `match` parameter or use a more specific exception | ||
| | ||
25 | raise PicklingError("Can't pickle") | ||
26 | | ||
27 | with pytest.raises(UnpicklingError): | ||
28 | raise PicklingError("Can't pickle") | ||
29 | | ||
30 | with pytest.raises(UnpicklingError): | ||
| ^^^^^^^^^^^^^^^ PT011 | ||
28 | raise UnpicklingError("Can't unpickle") | ||
31 | raise UnpicklingError("Can't unpickle") | ||
| | ||
|
||
|