---
source: crates/ruff/src/rules/flake8_pytest_style/mod.rs
---
PT009.py:11:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue`
   |
11 |         expr = 1
12 |         msg = "Must be True"
13 |         self.assertTrue(expr)  # Error
   |         ^^^^^^^^^^^^^^^ PT009
14 |         self.assertTrue(expr=expr)  # Error
15 |         self.assertTrue(expr, msg)  # Error
   |
   = help: Replace `assertTrue(...)` with `assert ...`

ℹ Suggested fix
8  8  |     def test_assert_true(self):
9  9  |         expr = 1
10 10 |         msg = "Must be True"
11    |-        self.assertTrue(expr)  # Error
   11 |+        assert expr  # Error
12 12 |         self.assertTrue(expr=expr)  # Error
13 13 |         self.assertTrue(expr, msg)  # Error
14 14 |         self.assertTrue(expr=expr, msg=msg)  # Error

PT009.py:12:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue`
   |
12 |         msg = "Must be True"
13 |         self.assertTrue(expr)  # Error
14 |         self.assertTrue(expr=expr)  # Error
   |         ^^^^^^^^^^^^^^^ PT009
15 |         self.assertTrue(expr, msg)  # Error
16 |         self.assertTrue(expr=expr, msg=msg)  # Error
   |
   = help: Replace `assertTrue(...)` with `assert ...`

ℹ Suggested fix
9  9  |         expr = 1
10 10 |         msg = "Must be True"
11 11 |         self.assertTrue(expr)  # Error
12    |-        self.assertTrue(expr=expr)  # Error
   12 |+        assert expr  # Error
13 13 |         self.assertTrue(expr, msg)  # Error
14 14 |         self.assertTrue(expr=expr, msg=msg)  # Error
15 15 |         self.assertTrue(msg=msg, expr=expr)  # Error

PT009.py:13:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue`
   |
13 |         self.assertTrue(expr)  # Error
14 |         self.assertTrue(expr=expr)  # Error
15 |         self.assertTrue(expr, msg)  # Error
   |         ^^^^^^^^^^^^^^^ PT009
16 |         self.assertTrue(expr=expr, msg=msg)  # Error
17 |         self.assertTrue(msg=msg, expr=expr)  # Error
   |
   = help: Replace `assertTrue(...)` with `assert ...`

ℹ Suggested fix
10 10 |         msg = "Must be True"
11 11 |         self.assertTrue(expr)  # Error
12 12 |         self.assertTrue(expr=expr)  # Error
13    |-        self.assertTrue(expr, msg)  # Error
   13 |+        assert expr, msg  # Error
14 14 |         self.assertTrue(expr=expr, msg=msg)  # Error
15 15 |         self.assertTrue(msg=msg, expr=expr)  # Error
16 16 |         self.assertTrue(*(expr, msg))  # Error, unfixable

PT009.py:14:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue`
   |
14 |         self.assertTrue(expr=expr)  # Error
15 |         self.assertTrue(expr, msg)  # Error
16 |         self.assertTrue(expr=expr, msg=msg)  # Error
   |         ^^^^^^^^^^^^^^^ PT009
17 |         self.assertTrue(msg=msg, expr=expr)  # Error
18 |         self.assertTrue(*(expr, msg))  # Error, unfixable
   |
   = help: Replace `assertTrue(...)` with `assert ...`

ℹ Suggested fix
11 11 |         self.assertTrue(expr)  # Error
12 12 |         self.assertTrue(expr=expr)  # Error
13 13 |         self.assertTrue(expr, msg)  # Error
14    |-        self.assertTrue(expr=expr, msg=msg)  # Error
   14 |+        assert expr, msg  # Error
15 15 |         self.assertTrue(msg=msg, expr=expr)  # Error
16 16 |         self.assertTrue(*(expr, msg))  # Error, unfixable
17 17 |         self.assertTrue(**{"expr": expr, "msg": msg})  # Error, unfixable

PT009.py:15:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue`
   |
15 |         self.assertTrue(expr, msg)  # Error
16 |         self.assertTrue(expr=expr, msg=msg)  # Error
17 |         self.assertTrue(msg=msg, expr=expr)  # Error
   |         ^^^^^^^^^^^^^^^ PT009
18 |         self.assertTrue(*(expr, msg))  # Error, unfixable
19 |         self.assertTrue(**{"expr": expr, "msg": msg})  # Error, unfixable
   |
   = help: Replace `assertTrue(...)` with `assert ...`

ℹ Suggested fix
12 12 |         self.assertTrue(expr=expr)  # Error
13 13 |         self.assertTrue(expr, msg)  # Error
14 14 |         self.assertTrue(expr=expr, msg=msg)  # Error
15    |-        self.assertTrue(msg=msg, expr=expr)  # Error
   15 |+        assert expr, msg  # Error
16 16 |         self.assertTrue(*(expr, msg))  # Error, unfixable
17 17 |         self.assertTrue(**{"expr": expr, "msg": msg})  # Error, unfixable
18 18 |         self.assertTrue(msg=msg, expr=expr, unexpected_arg=False)  # Error, unfixable

PT009.py:16:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue`
   |
16 |         self.assertTrue(expr=expr, msg=msg)  # Error
17 |         self.assertTrue(msg=msg, expr=expr)  # Error
18 |         self.assertTrue(*(expr, msg))  # Error, unfixable
   |         ^^^^^^^^^^^^^^^ PT009
19 |         self.assertTrue(**{"expr": expr, "msg": msg})  # Error, unfixable
20 |         self.assertTrue(msg=msg, expr=expr, unexpected_arg=False)  # Error, unfixable
   |
   = help: Replace `assertTrue(...)` with `assert ...`

PT009.py:17:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue`
   |
17 |         self.assertTrue(msg=msg, expr=expr)  # Error
18 |         self.assertTrue(*(expr, msg))  # Error, unfixable
19 |         self.assertTrue(**{"expr": expr, "msg": msg})  # Error, unfixable
   |         ^^^^^^^^^^^^^^^ PT009
20 |         self.assertTrue(msg=msg, expr=expr, unexpected_arg=False)  # Error, unfixable
21 |         self.assertTrue(msg=msg)  # Error, unfixable
   |
   = help: Replace `assertTrue(...)` with `assert ...`

PT009.py:18:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue`
   |
18 |         self.assertTrue(*(expr, msg))  # Error, unfixable
19 |         self.assertTrue(**{"expr": expr, "msg": msg})  # Error, unfixable
20 |         self.assertTrue(msg=msg, expr=expr, unexpected_arg=False)  # Error, unfixable
   |         ^^^^^^^^^^^^^^^ PT009
21 |         self.assertTrue(msg=msg)  # Error, unfixable
22 |         (
   |
   = help: Replace `assertTrue(...)` with `assert ...`

PT009.py:19:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue`
   |
19 |         self.assertTrue(**{"expr": expr, "msg": msg})  # Error, unfixable
20 |         self.assertTrue(msg=msg, expr=expr, unexpected_arg=False)  # Error, unfixable
21 |         self.assertTrue(msg=msg)  # Error, unfixable
   |         ^^^^^^^^^^^^^^^ PT009
22 |         (
23 |             self.assertIsNotNone(value)  # Error, unfixable
   |
   = help: Replace `assertTrue(...)` with `assert ...`

PT009.py:21:13: PT009 Use a regular `assert` instead of unittest-style `assertIsNotNone`
   |
21 |         self.assertTrue(msg=msg)  # Error, unfixable
22 |         (
23 |             self.assertIsNotNone(value)  # Error, unfixable
   |             ^^^^^^^^^^^^^^^^^^^^ PT009
24 |             if expect_condition
25 |             else self.assertIsNone(value)  # Error, unfixable
   |

PT009.py:23:18: PT009 Use a regular `assert` instead of unittest-style `assertIsNone`
   |
23 |             self.assertIsNotNone(value)  # Error, unfixable
24 |             if expect_condition
25 |             else self.assertIsNone(value)  # Error, unfixable
   |                  ^^^^^^^^^^^^^^^^^ PT009
26 |         )
27 |         return self.assertEqual(True,  False)  # Error, unfixable
   |

PT009.py:25:16: PT009 Use a regular `assert` instead of unittest-style `assertEqual`
   |
25 |             else self.assertIsNone(value)  # Error, unfixable
26 |         )
27 |         return self.assertEqual(True,  False)  # Error, unfixable
   |                ^^^^^^^^^^^^^^^^ PT009
28 | 
29 |     def test_assert_false(self):
   |

PT009.py:28:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertFalse`
   |
28 |     def test_assert_false(self):
29 |         self.assertFalse(True)  # Error
   |         ^^^^^^^^^^^^^^^^ PT009
30 | 
31 |     def test_assert_equal(self):
   |
   = help: Replace `assertFalse(...)` with `assert ...`

ℹ Suggested fix
25 25 |         return self.assertEqual(True,  False)  # Error, unfixable
26 26 | 
27 27 |     def test_assert_false(self):
28    |-        self.assertFalse(True)  # Error
   28 |+        assert not True  # Error
29 29 | 
30 30 |     def test_assert_equal(self):
31 31 |         self.assertEqual(1, 2)  # Error

PT009.py:31:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertEqual`
   |
31 |     def test_assert_equal(self):
32 |         self.assertEqual(1, 2)  # Error
   |         ^^^^^^^^^^^^^^^^ PT009
33 | 
34 |     def test_assert_not_equal(self):
   |
   = help: Replace `assertEqual(...)` with `assert ...`

ℹ Suggested fix
28 28 |         self.assertFalse(True)  # Error
29 29 | 
30 30 |     def test_assert_equal(self):
31    |-        self.assertEqual(1, 2)  # Error
   31 |+        assert 1 == 2  # Error
32 32 | 
33 33 |     def test_assert_not_equal(self):
34 34 |         self.assertNotEqual(1, 1)  # Error

PT009.py:34:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertNotEqual`
   |
34 |     def test_assert_not_equal(self):
35 |         self.assertNotEqual(1, 1)  # Error
   |         ^^^^^^^^^^^^^^^^^^^ PT009
36 | 
37 |     def test_assert_greater(self):
   |
   = help: Replace `assertNotEqual(...)` with `assert ...`

ℹ Suggested fix
31 31 |         self.assertEqual(1, 2)  # Error
32 32 | 
33 33 |     def test_assert_not_equal(self):
34    |-        self.assertNotEqual(1, 1)  # Error
   34 |+        assert 1 != 1  # Error
35 35 | 
36 36 |     def test_assert_greater(self):
37 37 |         self.assertGreater(1, 2)  # Error

PT009.py:37:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertGreater`
   |
37 |     def test_assert_greater(self):
38 |         self.assertGreater(1, 2)  # Error
   |         ^^^^^^^^^^^^^^^^^^ PT009
39 | 
40 |     def test_assert_greater_equal(self):
   |
   = help: Replace `assertGreater(...)` with `assert ...`

ℹ Suggested fix
34 34 |         self.assertNotEqual(1, 1)  # Error
35 35 | 
36 36 |     def test_assert_greater(self):
37    |-        self.assertGreater(1, 2)  # Error
   37 |+        assert 1 > 2  # Error
38 38 | 
39 39 |     def test_assert_greater_equal(self):
40 40 |         self.assertGreaterEqual(1, 2)  # Error

PT009.py:40:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertGreaterEqual`
   |
40 |     def test_assert_greater_equal(self):
41 |         self.assertGreaterEqual(1, 2)  # Error
   |         ^^^^^^^^^^^^^^^^^^^^^^^ PT009
42 | 
43 |     def test_assert_less(self):
   |
   = help: Replace `assertGreaterEqual(...)` with `assert ...`

ℹ Suggested fix
37 37 |         self.assertGreater(1, 2)  # Error
38 38 | 
39 39 |     def test_assert_greater_equal(self):
40    |-        self.assertGreaterEqual(1, 2)  # Error
   40 |+        assert 1 >= 2  # Error
41 41 | 
42 42 |     def test_assert_less(self):
43 43 |         self.assertLess(2, 1)  # Error

PT009.py:43:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertLess`
   |
43 |     def test_assert_less(self):
44 |         self.assertLess(2, 1)  # Error
   |         ^^^^^^^^^^^^^^^ PT009
45 | 
46 |     def test_assert_less_equal(self):
   |
   = help: Replace `assertLess(...)` with `assert ...`

ℹ Suggested fix
40 40 |         self.assertGreaterEqual(1, 2)  # Error
41 41 | 
42 42 |     def test_assert_less(self):
43    |-        self.assertLess(2, 1)  # Error
   43 |+        assert 2 < 1  # Error
44 44 | 
45 45 |     def test_assert_less_equal(self):
46 46 |         self.assertLessEqual(1, 2)  # Error

PT009.py:46:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertLessEqual`
   |
46 |     def test_assert_less_equal(self):
47 |         self.assertLessEqual(1, 2)  # Error
   |         ^^^^^^^^^^^^^^^^^^^^ PT009
48 | 
49 |     def test_assert_in(self):
   |
   = help: Replace `assertLessEqual(...)` with `assert ...`

ℹ Suggested fix
43 43 |         self.assertLess(2, 1)  # Error
44 44 | 
45 45 |     def test_assert_less_equal(self):
46    |-        self.assertLessEqual(1, 2)  # Error
   46 |+        assert 1 <= 2  # Error
47 47 | 
48 48 |     def test_assert_in(self):
49 49 |         self.assertIn(1, [2, 3])  # Error

PT009.py:49:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertIn`
   |
49 |     def test_assert_in(self):
50 |         self.assertIn(1, [2, 3])  # Error
   |         ^^^^^^^^^^^^^ PT009
51 | 
52 |     def test_assert_not_in(self):
   |
   = help: Replace `assertIn(...)` with `assert ...`

ℹ Suggested fix
46 46 |         self.assertLessEqual(1, 2)  # Error
47 47 | 
48 48 |     def test_assert_in(self):
49    |-        self.assertIn(1, [2, 3])  # Error
   49 |+        assert 1 in [2, 3]  # Error
50 50 | 
51 51 |     def test_assert_not_in(self):
52 52 |         self.assertNotIn(2, [2, 3])  # Error

PT009.py:52:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertNotIn`
   |
52 |     def test_assert_not_in(self):
53 |         self.assertNotIn(2, [2, 3])  # Error
   |         ^^^^^^^^^^^^^^^^ PT009
54 | 
55 |     def test_assert_is_none(self):
   |
   = help: Replace `assertNotIn(...)` with `assert ...`

ℹ Suggested fix
49 49 |         self.assertIn(1, [2, 3])  # Error
50 50 | 
51 51 |     def test_assert_not_in(self):
52    |-        self.assertNotIn(2, [2, 3])  # Error
   52 |+        assert 2 not in [2, 3]  # Error
53 53 | 
54 54 |     def test_assert_is_none(self):
55 55 |         self.assertIsNone(0)  # Error

PT009.py:55:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertIsNone`
   |
55 |     def test_assert_is_none(self):
56 |         self.assertIsNone(0)  # Error
   |         ^^^^^^^^^^^^^^^^^ PT009
57 | 
58 |     def test_assert_is_not_none(self):
   |
   = help: Replace `assertIsNone(...)` with `assert ...`

ℹ Suggested fix
52 52 |         self.assertNotIn(2, [2, 3])  # Error
53 53 | 
54 54 |     def test_assert_is_none(self):
55    |-        self.assertIsNone(0)  # Error
   55 |+        assert 0 is None  # Error
56 56 | 
57 57 |     def test_assert_is_not_none(self):
58 58 |         self.assertIsNotNone(0)  # Error

PT009.py:58:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertIsNotNone`
   |
58 |     def test_assert_is_not_none(self):
59 |         self.assertIsNotNone(0)  # Error
   |         ^^^^^^^^^^^^^^^^^^^^ PT009
60 | 
61 |     def test_assert_is(self):
   |
   = help: Replace `assertIsNotNone(...)` with `assert ...`

ℹ Suggested fix
55 55 |         self.assertIsNone(0)  # Error
56 56 | 
57 57 |     def test_assert_is_not_none(self):
58    |-        self.assertIsNotNone(0)  # Error
   58 |+        assert 0 is not None  # Error
59 59 | 
60 60 |     def test_assert_is(self):
61 61 |         self.assertIs([], [])  # Error

PT009.py:61:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertIs`
   |
61 |     def test_assert_is(self):
62 |         self.assertIs([], [])  # Error
   |         ^^^^^^^^^^^^^ PT009
63 | 
64 |     def test_assert_is_not(self):
   |
   = help: Replace `assertIs(...)` with `assert ...`

ℹ Suggested fix
58 58 |         self.assertIsNotNone(0)  # Error
59 59 | 
60 60 |     def test_assert_is(self):
61    |-        self.assertIs([], [])  # Error
   61 |+        assert [] is []  # Error
62 62 | 
63 63 |     def test_assert_is_not(self):
64 64 |         self.assertIsNot(1, 1)  # Error

PT009.py:64:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertIsNot`
   |
64 |     def test_assert_is_not(self):
65 |         self.assertIsNot(1, 1)  # Error
   |         ^^^^^^^^^^^^^^^^ PT009
66 | 
67 |     def test_assert_is_instance(self):
   |
   = help: Replace `assertIsNot(...)` with `assert ...`

ℹ Suggested fix
61 61 |         self.assertIs([], [])  # Error
62 62 | 
63 63 |     def test_assert_is_not(self):
64    |-        self.assertIsNot(1, 1)  # Error
   64 |+        assert 1 is not 1  # Error
65 65 | 
66 66 |     def test_assert_is_instance(self):
67 67 |         self.assertIsInstance(1, str)  # Error

PT009.py:67:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertIsInstance`
   |
67 |     def test_assert_is_instance(self):
68 |         self.assertIsInstance(1, str)  # Error
   |         ^^^^^^^^^^^^^^^^^^^^^ PT009
69 | 
70 |     def test_assert_is_not_instance(self):
   |
   = help: Replace `assertIsInstance(...)` with `assert ...`

ℹ Suggested fix
64 64 |         self.assertIsNot(1, 1)  # Error
65 65 | 
66 66 |     def test_assert_is_instance(self):
67    |-        self.assertIsInstance(1, str)  # Error
   67 |+        assert isinstance(1, str)  # Error
68 68 | 
69 69 |     def test_assert_is_not_instance(self):
70 70 |         self.assertNotIsInstance(1, int)  # Error

PT009.py:70:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertNotIsInstance`
   |
70 |     def test_assert_is_not_instance(self):
71 |         self.assertNotIsInstance(1, int)  # Error
   |         ^^^^^^^^^^^^^^^^^^^^^^^^ PT009
72 | 
73 |     def test_assert_regex(self):
   |
   = help: Replace `assertNotIsInstance(...)` with `assert ...`

ℹ Suggested fix
67 67 |         self.assertIsInstance(1, str)  # Error
68 68 | 
69 69 |     def test_assert_is_not_instance(self):
70    |-        self.assertNotIsInstance(1, int)  # Error
   70 |+        assert not isinstance(1, int)  # Error
71 71 | 
72 72 |     def test_assert_regex(self):
73 73 |         self.assertRegex("abc", r"def")  # Error

PT009.py:73:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertRegex`
   |
73 |     def test_assert_regex(self):
74 |         self.assertRegex("abc", r"def")  # Error
   |         ^^^^^^^^^^^^^^^^ PT009
75 | 
76 |     def test_assert_not_regex(self):
   |
   = help: Replace `assertRegex(...)` with `assert ...`

ℹ Suggested fix
70 70 |         self.assertNotIsInstance(1, int)  # Error
71 71 | 
72 72 |     def test_assert_regex(self):
73    |-        self.assertRegex("abc", r"def")  # Error
   73 |+        assert re.search("def", "abc")  # Error
74 74 | 
75 75 |     def test_assert_not_regex(self):
76 76 |         self.assertNotRegex("abc", r"abc")  # Error

PT009.py:76:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertNotRegex`
   |
76 |     def test_assert_not_regex(self):
77 |         self.assertNotRegex("abc", r"abc")  # Error
   |         ^^^^^^^^^^^^^^^^^^^ PT009
78 | 
79 |     def test_assert_regexp_matches(self):
   |
   = help: Replace `assertNotRegex(...)` with `assert ...`

ℹ Suggested fix
73 73 |         self.assertRegex("abc", r"def")  # Error
74 74 | 
75 75 |     def test_assert_not_regex(self):
76    |-        self.assertNotRegex("abc", r"abc")  # Error
   76 |+        assert not re.search("abc", "abc")  # Error
77 77 | 
78 78 |     def test_assert_regexp_matches(self):
79 79 |         self.assertRegexpMatches("abc", r"def")  # Error

PT009.py:79:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertRegexpMatches`
   |
79 |     def test_assert_regexp_matches(self):
80 |         self.assertRegexpMatches("abc", r"def")  # Error
   |         ^^^^^^^^^^^^^^^^^^^^^^^^ PT009
81 | 
82 |     def test_assert_not_regexp_matches(self):
   |
   = help: Replace `assertRegexpMatches(...)` with `assert ...`

ℹ Suggested fix
76 76 |         self.assertNotRegex("abc", r"abc")  # Error
77 77 | 
78 78 |     def test_assert_regexp_matches(self):
79    |-        self.assertRegexpMatches("abc", r"def")  # Error
   79 |+        assert re.search("def", "abc")  # Error
80 80 | 
81 81 |     def test_assert_not_regexp_matches(self):
82 82 |         self.assertNotRegex("abc", r"abc")  # Error

PT009.py:82:9: PT009 [*] Use a regular `assert` instead of unittest-style `assertNotRegex`
   |
82 |     def test_assert_not_regexp_matches(self):
83 |         self.assertNotRegex("abc", r"abc")  # Error
   |         ^^^^^^^^^^^^^^^^^^^ PT009
   |
   = help: Replace `assertNotRegex(...)` with `assert ...`

ℹ Suggested fix
79 79 |         self.assertRegexpMatches("abc", r"def")  # Error
80 80 | 
81 81 |     def test_assert_not_regexp_matches(self):
82    |-        self.assertNotRegex("abc", r"abc")  # Error
   82 |+        assert not re.search("abc", "abc")  # Error


