---
source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs
---
PT027 [*] Use `pytest.raises` instead of unittest-style `assertRaises`
  --> PT027_1.py:11:14
   |
10 |     def test_errors(self):
11 |         with self.assertRaises(ValueError):
   |              ^^^^^^^^^^^^^^^^^
12 |             raise ValueError
   |
help: Replace `assertRaises` with `pytest.raises`
   |
10 |     def test_errors(self):
   -         with self.assertRaises(ValueError):
11 +         with pytest.raises(ValueError):
12 |             raise ValueError
   |
note: This is an unsafe fix and may change runtime behavior

PT027 [*] Use `pytest.raises` instead of unittest-style `assertRaises`
  --> PT027_1.py:15:14
   |
14 |     def test_rewrite_references(self):
15 |         with self.assertRaises(ValueError) as e:
   |              ^^^^^^^^^^^^^^^^^
16 |             raise ValueError
   |
help: Replace `assertRaises` with `pytest.raises`
   |
14 |     def test_rewrite_references(self):
   -         with self.assertRaises(ValueError) as e:
15 +         with pytest.raises(ValueError) as e:
16 |             raise ValueError
17 |
18 |         print(e.foo)
   -         print(e.exception)
19 +         print(e.value)
20 |
   |
note: This is an unsafe fix and may change runtime behavior

PT027 [*] Use `pytest.raises` instead of unittest-style `assertRaises`
  --> PT027_1.py:22:14
   |
21 |     def test_rewrite_references_multiple_items(self):
22 |         with self.assertRaises(ValueError) as e1, \
   |              ^^^^^^^^^^^^^^^^^
23 |             self.assertRaises(ValueError) as e2:
24 |             raise ValueError
   |
help: Replace `assertRaises` with `pytest.raises`
   |
21 |     def test_rewrite_references_multiple_items(self):
   -         with self.assertRaises(ValueError) as e1, \
22 +         with pytest.raises(ValueError) as e1, \
23 |             self.assertRaises(ValueError) as e2:
24 |             raise ValueError
25 |
26 |         print(e1.foo)
   -         print(e1.exception)
27 +         print(e1.value)
28 |
   |
note: This is an unsafe fix and may change runtime behavior

PT027 [*] Use `pytest.raises` instead of unittest-style `assertRaises`
  --> PT027_1.py:23:13
   |
21 |     def test_rewrite_references_multiple_items(self):
22 |         with self.assertRaises(ValueError) as e1, \
23 |             self.assertRaises(ValueError) as e2:
   |             ^^^^^^^^^^^^^^^^^
24 |             raise ValueError
   |
help: Replace `assertRaises` with `pytest.raises`
   |
22 |         with self.assertRaises(ValueError) as e1, \
   -             self.assertRaises(ValueError) as e2:
23 +             pytest.raises(ValueError) as e2:
24 |             raise ValueError
--------------------------------------------------------------------------------
29 |         print(e2.foo)
   -         print(e2.exception)
30 +         print(e2.value)
31 |
   |
note: This is an unsafe fix and may change runtime behavior

PT027 [*] Use `pytest.raises` instead of unittest-style `assertRaises`
  --> PT027_1.py:33:14
   |
32 |     def test_rewrite_references_multiple_items_nested(self):
33 |         with self.assertRaises(ValueError) as e1, \
   |              ^^^^^^^^^^^^^^^^^
34 |             foo(self.assertRaises(ValueError)) as e2:
35 |             raise ValueError
   |
help: Replace `assertRaises` with `pytest.raises`
   |
32 |     def test_rewrite_references_multiple_items_nested(self):
   -         with self.assertRaises(ValueError) as e1, \
33 +         with pytest.raises(ValueError) as e1, \
34 |             foo(self.assertRaises(ValueError)) as e2:
35 |             raise ValueError
36 |
37 |         print(e1.foo)
   -         print(e1.exception)
38 +         print(e1.value)
39 |
   |
note: This is an unsafe fix and may change runtime behavior

PT027 [*] Use `pytest.raises` instead of unittest-style `assertRaises`
  --> PT027_1.py:34:17
   |
32 |     def test_rewrite_references_multiple_items_nested(self):
33 |         with self.assertRaises(ValueError) as e1, \
34 |             foo(self.assertRaises(ValueError)) as e2:
   |                 ^^^^^^^^^^^^^^^^^
35 |             raise ValueError
   |
help: Replace `assertRaises` with `pytest.raises`
   |
33 |         with self.assertRaises(ValueError) as e1, \
   -             foo(self.assertRaises(ValueError)) as e2:
34 +             foo(pytest.raises(ValueError)) as e2:
35 |             raise ValueError
   |
note: This is an unsafe fix and may change runtime behavior
