Skip to content

Commit 74e7cc8

Browse files
test: add a test example
1 parent b10dd82 commit 74e7cc8

5 files changed

+111
-104
lines changed

crates/ruff_linter/resources/test/fixtures/flake8_pytest_style/PT011.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ def test_ok_different_error_from_config():
1414
raise ZeroDivisionError("Can't divide by 0")
1515

1616

17+
def test_ok_legacy_form():
18+
def func():
19+
raise ValueError("Can't divide by 0")
20+
21+
pytest.raises(ValueError, func).match("Can't divide by 0")
22+
23+
1724
def test_error_no_argument_given():
1825
with pytest.raises(ValueError):
1926
raise ValueError("Can't divide 1 by 0")
Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
11
---
22
source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs
33
---
4-
PT011.py:18:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
4+
PT011.py:25:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
55
|
6-
17 | def test_error_no_argument_given():
7-
18 | with pytest.raises(ValueError):
6+
24 | def test_error_no_argument_given():
7+
25 | with pytest.raises(ValueError):
88
| ^^^^^^^^^^ PT011
9-
19 | raise ValueError("Can't divide 1 by 0")
9+
26 | raise ValueError("Can't divide 1 by 0")
1010
|
1111

12-
PT011.py:21:43: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
12+
PT011.py:28:43: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
1313
|
14-
19 | raise ValueError("Can't divide 1 by 0")
15-
20 |
16-
21 | with pytest.raises(expected_exception=ValueError):
14+
26 | raise ValueError("Can't divide 1 by 0")
15+
27 |
16+
28 | with pytest.raises(expected_exception=ValueError):
1717
| ^^^^^^^^^^ PT011
18-
22 | raise ValueError("Can't divide 1 by 0")
18+
29 | raise ValueError("Can't divide 1 by 0")
1919
|
2020

21-
PT011.py:24:24: PT011 `pytest.raises(socket.error)` is too broad, set the `match` parameter or use a more specific exception
21+
PT011.py:31:24: PT011 `pytest.raises(socket.error)` is too broad, set the `match` parameter or use a more specific exception
2222
|
23-
22 | raise ValueError("Can't divide 1 by 0")
24-
23 |
25-
24 | with pytest.raises(socket.error):
23+
29 | raise ValueError("Can't divide 1 by 0")
24+
30 |
25+
31 | with pytest.raises(socket.error):
2626
| ^^^^^^^^^^^^ PT011
27-
25 | raise ValueError("Can't divide 1 by 0")
27+
32 | raise ValueError("Can't divide 1 by 0")
2828
|
2929

30-
PT011.py:35:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
30+
PT011.py:42:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
3131
|
32-
34 | def test_error_match_is_empty():
33-
35 | with pytest.raises(ValueError, match=None):
32+
41 | def test_error_match_is_empty():
33+
42 | with pytest.raises(ValueError, match=None):
3434
| ^^^^^^^^^^ PT011
35-
36 | raise ValueError("Can't divide 1 by 0")
35+
43 | raise ValueError("Can't divide 1 by 0")
3636
|
3737

38-
PT011.py:38:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
38+
PT011.py:45:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
3939
|
40-
36 | raise ValueError("Can't divide 1 by 0")
41-
37 |
42-
38 | with pytest.raises(ValueError, match=""):
40+
43 | raise ValueError("Can't divide 1 by 0")
41+
44 |
42+
45 | with pytest.raises(ValueError, match=""):
4343
| ^^^^^^^^^^ PT011
44-
39 | raise ValueError("Can't divide 1 by 0")
44+
46 | raise ValueError("Can't divide 1 by 0")
4545
|
4646

47-
PT011.py:41:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
47+
PT011.py:48:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
4848
|
49-
39 | raise ValueError("Can't divide 1 by 0")
50-
40 |
51-
41 | with pytest.raises(ValueError, match=f""):
49+
46 | raise ValueError("Can't divide 1 by 0")
50+
47 |
51+
48 | with pytest.raises(ValueError, match=f""):
5252
| ^^^^^^^^^^ PT011
53-
42 | raise ValueError("Can't divide 1 by 0")
53+
49 | raise ValueError("Can't divide 1 by 0")
5454
|

crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT011_extend_broad_exceptions.snap

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,54 @@ PT011.py:13:24: PT011 `pytest.raises(ZeroDivisionError)` is too broad, set the `
99
14 | raise ZeroDivisionError("Can't divide by 0")
1010
|
1111

12-
PT011.py:18:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
12+
PT011.py:25:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
1313
|
14-
17 | def test_error_no_argument_given():
15-
18 | with pytest.raises(ValueError):
14+
24 | def test_error_no_argument_given():
15+
25 | with pytest.raises(ValueError):
1616
| ^^^^^^^^^^ PT011
17-
19 | raise ValueError("Can't divide 1 by 0")
17+
26 | raise ValueError("Can't divide 1 by 0")
1818
|
1919

20-
PT011.py:21:43: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
20+
PT011.py:28:43: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
2121
|
22-
19 | raise ValueError("Can't divide 1 by 0")
23-
20 |
24-
21 | with pytest.raises(expected_exception=ValueError):
22+
26 | raise ValueError("Can't divide 1 by 0")
23+
27 |
24+
28 | with pytest.raises(expected_exception=ValueError):
2525
| ^^^^^^^^^^ PT011
26-
22 | raise ValueError("Can't divide 1 by 0")
26+
29 | raise ValueError("Can't divide 1 by 0")
2727
|
2828

29-
PT011.py:24:24: PT011 `pytest.raises(socket.error)` is too broad, set the `match` parameter or use a more specific exception
29+
PT011.py:31:24: PT011 `pytest.raises(socket.error)` is too broad, set the `match` parameter or use a more specific exception
3030
|
31-
22 | raise ValueError("Can't divide 1 by 0")
32-
23 |
33-
24 | with pytest.raises(socket.error):
31+
29 | raise ValueError("Can't divide 1 by 0")
32+
30 |
33+
31 | with pytest.raises(socket.error):
3434
| ^^^^^^^^^^^^ PT011
35-
25 | raise ValueError("Can't divide 1 by 0")
35+
32 | raise ValueError("Can't divide 1 by 0")
3636
|
3737

38-
PT011.py:35:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
38+
PT011.py:42:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
3939
|
40-
34 | def test_error_match_is_empty():
41-
35 | with pytest.raises(ValueError, match=None):
40+
41 | def test_error_match_is_empty():
41+
42 | with pytest.raises(ValueError, match=None):
4242
| ^^^^^^^^^^ PT011
43-
36 | raise ValueError("Can't divide 1 by 0")
43+
43 | raise ValueError("Can't divide 1 by 0")
4444
|
4545

46-
PT011.py:38:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
46+
PT011.py:45:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
4747
|
48-
36 | raise ValueError("Can't divide 1 by 0")
49-
37 |
50-
38 | with pytest.raises(ValueError, match=""):
48+
43 | raise ValueError("Can't divide 1 by 0")
49+
44 |
50+
45 | with pytest.raises(ValueError, match=""):
5151
| ^^^^^^^^^^ PT011
52-
39 | raise ValueError("Can't divide 1 by 0")
52+
46 | raise ValueError("Can't divide 1 by 0")
5353
|
5454

55-
PT011.py:41:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
55+
PT011.py:48:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
5656
|
57-
39 | raise ValueError("Can't divide 1 by 0")
58-
40 |
59-
41 | with pytest.raises(ValueError, match=f""):
57+
46 | raise ValueError("Can't divide 1 by 0")
58+
47 |
59+
48 | with pytest.raises(ValueError, match=f""):
6060
| ^^^^^^^^^^ PT011
61-
42 | raise ValueError("Can't divide 1 by 0")
61+
49 | raise ValueError("Can't divide 1 by 0")
6262
|

crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT011_glob_all.snap

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,72 +9,72 @@ PT011.py:13:24: PT011 `pytest.raises(ZeroDivisionError)` is too broad, set the `
99
14 | raise ZeroDivisionError("Can't divide by 0")
1010
|
1111

12-
PT011.py:18:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
12+
PT011.py:25:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
1313
|
14-
17 | def test_error_no_argument_given():
15-
18 | with pytest.raises(ValueError):
14+
24 | def test_error_no_argument_given():
15+
25 | with pytest.raises(ValueError):
1616
| ^^^^^^^^^^ PT011
17-
19 | raise ValueError("Can't divide 1 by 0")
17+
26 | raise ValueError("Can't divide 1 by 0")
1818
|
1919

20-
PT011.py:21:43: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
20+
PT011.py:28:43: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
2121
|
22-
19 | raise ValueError("Can't divide 1 by 0")
23-
20 |
24-
21 | with pytest.raises(expected_exception=ValueError):
22+
26 | raise ValueError("Can't divide 1 by 0")
23+
27 |
24+
28 | with pytest.raises(expected_exception=ValueError):
2525
| ^^^^^^^^^^ PT011
26-
22 | raise ValueError("Can't divide 1 by 0")
26+
29 | raise ValueError("Can't divide 1 by 0")
2727
|
2828

29-
PT011.py:24:24: PT011 `pytest.raises(socket.error)` is too broad, set the `match` parameter or use a more specific exception
29+
PT011.py:31:24: PT011 `pytest.raises(socket.error)` is too broad, set the `match` parameter or use a more specific exception
3030
|
31-
22 | raise ValueError("Can't divide 1 by 0")
32-
23 |
33-
24 | with pytest.raises(socket.error):
31+
29 | raise ValueError("Can't divide 1 by 0")
32+
30 |
33+
31 | with pytest.raises(socket.error):
3434
| ^^^^^^^^^^^^ PT011
35-
25 | raise ValueError("Can't divide 1 by 0")
35+
32 | raise ValueError("Can't divide 1 by 0")
3636
|
3737

38-
PT011.py:27:24: PT011 `pytest.raises(pickle.PicklingError)` is too broad, set the `match` parameter or use a more specific exception
38+
PT011.py:34:24: PT011 `pytest.raises(pickle.PicklingError)` is too broad, set the `match` parameter or use a more specific exception
3939
|
40-
25 | raise ValueError("Can't divide 1 by 0")
41-
26 |
42-
27 | with pytest.raises(PicklingError):
40+
32 | raise ValueError("Can't divide 1 by 0")
41+
33 |
42+
34 | with pytest.raises(PicklingError):
4343
| ^^^^^^^^^^^^^ PT011
44-
28 | raise PicklingError("Can't pickle")
44+
35 | raise PicklingError("Can't pickle")
4545
|
4646

47-
PT011.py:30:24: PT011 `pytest.raises(pickle.UnpicklingError)` is too broad, set the `match` parameter or use a more specific exception
47+
PT011.py:37:24: PT011 `pytest.raises(pickle.UnpicklingError)` is too broad, set the `match` parameter or use a more specific exception
4848
|
49-
28 | raise PicklingError("Can't pickle")
50-
29 |
51-
30 | with pytest.raises(UnpicklingError):
49+
35 | raise PicklingError("Can't pickle")
50+
36 |
51+
37 | with pytest.raises(UnpicklingError):
5252
| ^^^^^^^^^^^^^^^ PT011
53-
31 | raise UnpicklingError("Can't unpickle")
53+
38 | raise UnpicklingError("Can't unpickle")
5454
|
5555

56-
PT011.py:35:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
56+
PT011.py:42:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
5757
|
58-
34 | def test_error_match_is_empty():
59-
35 | with pytest.raises(ValueError, match=None):
58+
41 | def test_error_match_is_empty():
59+
42 | with pytest.raises(ValueError, match=None):
6060
| ^^^^^^^^^^ PT011
61-
36 | raise ValueError("Can't divide 1 by 0")
61+
43 | raise ValueError("Can't divide 1 by 0")
6262
|
6363

64-
PT011.py:38:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
64+
PT011.py:45:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
6565
|
66-
36 | raise ValueError("Can't divide 1 by 0")
67-
37 |
68-
38 | with pytest.raises(ValueError, match=""):
66+
43 | raise ValueError("Can't divide 1 by 0")
67+
44 |
68+
45 | with pytest.raises(ValueError, match=""):
6969
| ^^^^^^^^^^ PT011
70-
39 | raise ValueError("Can't divide 1 by 0")
70+
46 | raise ValueError("Can't divide 1 by 0")
7171
|
7272

73-
PT011.py:41:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
73+
PT011.py:48:24: PT011 `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception
7474
|
75-
39 | raise ValueError("Can't divide 1 by 0")
76-
40 |
77-
41 | with pytest.raises(ValueError, match=f""):
75+
46 | raise ValueError("Can't divide 1 by 0")
76+
47 |
77+
48 | with pytest.raises(ValueError, match=f""):
7878
| ^^^^^^^^^^ PT011
79-
42 | raise ValueError("Can't divide 1 by 0")
79+
49 | raise ValueError("Can't divide 1 by 0")
8080
|
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
---
22
source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs
33
---
4-
PT011.py:27:24: PT011 `pytest.raises(pickle.PicklingError)` is too broad, set the `match` parameter or use a more specific exception
4+
PT011.py:34:24: PT011 `pytest.raises(pickle.PicklingError)` is too broad, set the `match` parameter or use a more specific exception
55
|
6-
25 | raise ValueError("Can't divide 1 by 0")
7-
26 |
8-
27 | with pytest.raises(PicklingError):
6+
32 | raise ValueError("Can't divide 1 by 0")
7+
33 |
8+
34 | with pytest.raises(PicklingError):
99
| ^^^^^^^^^^^^^ PT011
10-
28 | raise PicklingError("Can't pickle")
10+
35 | raise PicklingError("Can't pickle")
1111
|
1212

13-
PT011.py:30:24: PT011 `pytest.raises(pickle.UnpicklingError)` is too broad, set the `match` parameter or use a more specific exception
13+
PT011.py:37:24: PT011 `pytest.raises(pickle.UnpicklingError)` is too broad, set the `match` parameter or use a more specific exception
1414
|
15-
28 | raise PicklingError("Can't pickle")
16-
29 |
17-
30 | with pytest.raises(UnpicklingError):
15+
35 | raise PicklingError("Can't pickle")
16+
36 |
17+
37 | with pytest.raises(UnpicklingError):
1818
| ^^^^^^^^^^^^^^^ PT011
19-
31 | raise UnpicklingError("Can't unpickle")
19+
38 | raise UnpicklingError("Can't unpickle")
2020
|

0 commit comments

Comments
 (0)