---
source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs
---
PT027 [*] Use `pytest.raises` instead of unittest-style `assertRaises`
 --> PT027_0.py:6:14
  |
4 | class Test(unittest.TestCase):
5 |     def test_errors(self):
6 |         with self.assertRaises(ValueError):
  |              ^^^^^^^^^^^^^^^^^
7 |             raise ValueError
8 |         with self.assertRaises(expected_exception=ValueError):
  |
help: Replace `assertRaises` with `pytest.raises`
  |
1 | import unittest
2 + import pytest
3 |
4 |
5 | class Test(unittest.TestCase):
6 |     def test_errors(self):
  -         with self.assertRaises(ValueError):
7 +         with pytest.raises(ValueError):
8 |             raise ValueError
  |
note: This is an unsafe fix and may change runtime behavior

PT027 [*] Use `pytest.raises` instead of unittest-style `assertRaises`
 --> PT027_0.py:8:14
  |
6 |         with self.assertRaises(ValueError):
7 |             raise ValueError
8 |         with self.assertRaises(expected_exception=ValueError):
  |              ^^^^^^^^^^^^^^^^^
9 |             raise ValueError
  |
help: Replace `assertRaises` with `pytest.raises`
   |
1  | import unittest
2  + import pytest
3  |
--------------------------------------------------------------------------------
8  |             raise ValueError
   -         with self.assertRaises(expected_exception=ValueError):
9  +         with pytest.raises(ValueError):
10 |             raise ValueError
   |
note: This is an unsafe fix and may change runtime behavior

PT027 [*] Use `pytest.raises` instead of unittest-style `failUnlessRaises`
  --> PT027_0.py:11:14
   |
 9 |             raise ValueError
10 |
11 |         with self.failUnlessRaises(ValueError):
   |              ^^^^^^^^^^^^^^^^^^^^^
12 |             raise ValueError
   |
help: Replace `failUnlessRaises` with `pytest.raises`
   |
1  | import unittest
2  + import pytest
3  |
--------------------------------------------------------------------------------
11 |
   -         with self.failUnlessRaises(ValueError):
12 +         with pytest.raises(ValueError):
13 |             raise ValueError
   |
note: This is an unsafe fix and may change runtime behavior

PT027 [*] Use `pytest.raises` instead of unittest-style `assertRaisesRegex`
  --> PT027_0.py:14:14
   |
12 |             raise ValueError
13 |
14 |         with self.assertRaisesRegex(ValueError, "test"):
   |              ^^^^^^^^^^^^^^^^^^^^^^
15 |             raise ValueError("test")
   |
help: Replace `assertRaisesRegex` with `pytest.raises`
   |
1  | import unittest
2  + import pytest
3  |
--------------------------------------------------------------------------------
14 |
   -         with self.assertRaisesRegex(ValueError, "test"):
15 +         with pytest.raises(ValueError, match="test"):
16 |             raise ValueError("test")
   |
note: This is an unsafe fix and may change runtime behavior

PT027 [*] Use `pytest.raises` instead of unittest-style `assertRaisesRegex`
  --> PT027_0.py:17:14
   |
15 |             raise ValueError("test")
16 |
17 |         with self.assertRaisesRegex(ValueError, expected_regex="test"):
   |              ^^^^^^^^^^^^^^^^^^^^^^
18 |             raise ValueError("test")
   |
help: Replace `assertRaisesRegex` with `pytest.raises`
   |
1  | import unittest
2  + import pytest
3  |
--------------------------------------------------------------------------------
17 |
   -         with self.assertRaisesRegex(ValueError, expected_regex="test"):
18 +         with pytest.raises(ValueError, match="test"):
19 |             raise ValueError("test")
   |
note: This is an unsafe fix and may change runtime behavior

PT027 [*] Use `pytest.raises` instead of unittest-style `assertRaisesRegex`
  --> PT027_0.py:20:14
   |
18 |             raise ValueError("test")
19 |
20 |         with self.assertRaisesRegex(
   |              ^^^^^^^^^^^^^^^^^^^^^^
21 |             expected_exception=ValueError, expected_regex="test"
22 |         ):
   |
help: Replace `assertRaisesRegex` with `pytest.raises`
   |
1  | import unittest
2  + import pytest
3  |
--------------------------------------------------------------------------------
20 |
   -         with self.assertRaisesRegex(
   -             expected_exception=ValueError, expected_regex="test"
   -         ):
21 +         with pytest.raises(ValueError, match="test"):
22 |             raise ValueError("test")
   |
note: This is an unsafe fix and may change runtime behavior

PT027 [*] Use `pytest.raises` instead of unittest-style `assertRaisesRegex`
  --> PT027_0.py:25:14
   |
23 |             raise ValueError("test")
24 |
25 |         with self.assertRaisesRegex(
   |              ^^^^^^^^^^^^^^^^^^^^^^
26 |             expected_regex="test", expected_exception=ValueError
27 |         ):
   |
help: Replace `assertRaisesRegex` with `pytest.raises`
   |
1  | import unittest
2  + import pytest
3  |
--------------------------------------------------------------------------------
25 |
   -         with self.assertRaisesRegex(
   -             expected_regex="test", expected_exception=ValueError
   -         ):
26 +         with pytest.raises(ValueError, match="test"):
27 |             raise ValueError("test")
   |
note: This is an unsafe fix and may change runtime behavior

PT027 [*] Use `pytest.raises` instead of unittest-style `assertRaisesRegexp`
  --> PT027_0.py:30:14
   |
28 |             raise ValueError("test")
29 |
30 |         with self.assertRaisesRegexp(ValueError, "test"):
   |              ^^^^^^^^^^^^^^^^^^^^^^^
31 |             raise ValueError("test")
   |
help: Replace `assertRaisesRegexp` with `pytest.raises`
   |
1  | import unittest
2  + import pytest
3  |
--------------------------------------------------------------------------------
30 |
   -         with self.assertRaisesRegexp(ValueError, "test"):
31 +         with pytest.raises(ValueError, match="test"):
32 |             raise ValueError("test")
   |
note: This is an unsafe fix and may change runtime behavior

PT027 Use `pytest.raises` instead of unittest-style `assertRaises`
  --> PT027_0.py:34:14
   |
33 |     def test_unfixable_errors(self):
34 |         with self.assertRaises(ValueError, msg="msg"):
   |              ^^^^^^^^^^^^^^^^^
35 |             raise ValueError
   |
help: Replace `assertRaises` with `pytest.raises`

PT027 Use `pytest.raises` instead of unittest-style `assertRaises`
  --> PT027_0.py:37:14
   |
35 |             raise ValueError
36 |
37 |         with self.assertRaises(
   |              ^^^^^^^^^^^^^^^^^
38 |             # comment
39 |             ValueError
   |
help: Replace `assertRaises` with `pytest.raises`

PT027 Use `pytest.raises` instead of unittest-style `assertRaises`
  --> PT027_0.py:44:13
   |
43 |           with (
44 | /             self
45 | |             # comment
46 | |             .assertRaises(ValueError)
   | |_________________________^
47 |           ):
48 |               raise ValueError
   |
help: Replace `assertRaises` with `pytest.raises`
