---
source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs
---
PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue`
  --> PT009.py:11:9
   |
 9 |         expr = 1
10 |         msg = "Must be True"
11 |         self.assertTrue(expr)  # Error
   |         ^^^^^^^^^^^^^^^
12 |         self.assertTrue(expr=expr)  # Error
13 |         self.assertTrue(expr, msg)  # Error
   |
help: Replace `assertTrue(...)` with `assert ...`
   |
10 |         msg = "Must be True"
   -         self.assertTrue(expr)  # Error
11 +         assert expr  # Error
12 |         self.assertTrue(expr=expr)  # Error
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue`
  --> PT009.py:12:9
   |
10 |         msg = "Must be True"
11 |         self.assertTrue(expr)  # Error
12 |         self.assertTrue(expr=expr)  # Error
   |         ^^^^^^^^^^^^^^^
13 |         self.assertTrue(expr, msg)  # Error
14 |         self.assertTrue(expr=expr, msg=msg)  # Error
   |
help: Replace `assertTrue(...)` with `assert ...`
   |
11 |         self.assertTrue(expr)  # Error
   -         self.assertTrue(expr=expr)  # Error
12 +         assert expr  # Error
13 |         self.assertTrue(expr, msg)  # Error
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue`
  --> PT009.py:13:9
   |
11 |         self.assertTrue(expr)  # Error
12 |         self.assertTrue(expr=expr)  # Error
13 |         self.assertTrue(expr, msg)  # Error
   |         ^^^^^^^^^^^^^^^
14 |         self.assertTrue(expr=expr, msg=msg)  # Error
15 |         self.assertTrue(msg=msg, expr=expr)  # Error
   |
help: Replace `assertTrue(...)` with `assert ...`
   |
12 |         self.assertTrue(expr=expr)  # Error
   -         self.assertTrue(expr, msg)  # Error
13 +         assert expr, msg  # Error
14 |         self.assertTrue(expr=expr, msg=msg)  # Error
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue`
  --> PT009.py:14:9
   |
12 |         self.assertTrue(expr=expr)  # Error
13 |         self.assertTrue(expr, msg)  # Error
14 |         self.assertTrue(expr=expr, msg=msg)  # Error
   |         ^^^^^^^^^^^^^^^
15 |         self.assertTrue(msg=msg, expr=expr)  # Error
16 |         self.assertTrue(*(expr, msg))  # Error, unfixable
   |
help: Replace `assertTrue(...)` with `assert ...`
   |
13 |         self.assertTrue(expr, msg)  # Error
   -         self.assertTrue(expr=expr, msg=msg)  # Error
14 +         assert expr, msg  # Error
15 |         self.assertTrue(msg=msg, expr=expr)  # Error
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue`
  --> PT009.py:15:9
   |
13 |         self.assertTrue(expr, msg)  # Error
14 |         self.assertTrue(expr=expr, msg=msg)  # Error
15 |         self.assertTrue(msg=msg, expr=expr)  # Error
   |         ^^^^^^^^^^^^^^^
16 |         self.assertTrue(*(expr, msg))  # Error, unfixable
17 |         self.assertTrue(**{"expr": expr, "msg": msg})  # Error, unfixable
   |
help: Replace `assertTrue(...)` with `assert ...`
   |
14 |         self.assertTrue(expr=expr, msg=msg)  # Error
   -         self.assertTrue(msg=msg, expr=expr)  # Error
15 +         assert expr, msg  # Error
16 |         self.assertTrue(*(expr, msg))  # Error, unfixable
   |
note: This is an unsafe fix and may change runtime behavior

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

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

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

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

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

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

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

PT009 [*] Use a regular `assert` instead of unittest-style `assertFalse`
  --> PT009.py:28:9
   |
27 |     def test_assert_false(self):
28 |         self.assertFalse(True)  # Error
   |         ^^^^^^^^^^^^^^^^
29 |
30 |     def test_assert_equal(self):
   |
help: Replace `assertFalse(...)` with `assert ...`
   |
27 |     def test_assert_false(self):
   -         self.assertFalse(True)  # Error
28 +         assert not True  # Error
29 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertEqual`
  --> PT009.py:31:9
   |
30 |     def test_assert_equal(self):
31 |         self.assertEqual(1, 2)  # Error
   |         ^^^^^^^^^^^^^^^^
32 |
33 |     def test_assert_not_equal(self):
   |
help: Replace `assertEqual(...)` with `assert ...`
   |
30 |     def test_assert_equal(self):
   -         self.assertEqual(1, 2)  # Error
31 +         assert 1 == 2  # Error
32 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertNotEqual`
  --> PT009.py:34:9
   |
33 |     def test_assert_not_equal(self):
34 |         self.assertNotEqual(1, 1)  # Error
   |         ^^^^^^^^^^^^^^^^^^^
35 |
36 |     def test_assert_greater(self):
   |
help: Replace `assertNotEqual(...)` with `assert ...`
   |
33 |     def test_assert_not_equal(self):
   -         self.assertNotEqual(1, 1)  # Error
34 +         assert 1 != 1  # Error
35 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertGreater`
  --> PT009.py:37:9
   |
36 |     def test_assert_greater(self):
37 |         self.assertGreater(1, 2)  # Error
   |         ^^^^^^^^^^^^^^^^^^
38 |
39 |     def test_assert_greater_equal(self):
   |
help: Replace `assertGreater(...)` with `assert ...`
   |
36 |     def test_assert_greater(self):
   -         self.assertGreater(1, 2)  # Error
37 +         assert 1 > 2  # Error
38 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertGreaterEqual`
  --> PT009.py:40:9
   |
39 |     def test_assert_greater_equal(self):
40 |         self.assertGreaterEqual(1, 2)  # Error
   |         ^^^^^^^^^^^^^^^^^^^^^^^
41 |
42 |     def test_assert_less(self):
   |
help: Replace `assertGreaterEqual(...)` with `assert ...`
   |
39 |     def test_assert_greater_equal(self):
   -         self.assertGreaterEqual(1, 2)  # Error
40 +         assert 1 >= 2  # Error
41 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertLess`
  --> PT009.py:43:9
   |
42 |     def test_assert_less(self):
43 |         self.assertLess(2, 1)  # Error
   |         ^^^^^^^^^^^^^^^
44 |
45 |     def test_assert_less_equal(self):
   |
help: Replace `assertLess(...)` with `assert ...`
   |
42 |     def test_assert_less(self):
   -         self.assertLess(2, 1)  # Error
43 +         assert 2 < 1  # Error
44 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertLessEqual`
  --> PT009.py:46:9
   |
45 |     def test_assert_less_equal(self):
46 |         self.assertLessEqual(1, 2)  # Error
   |         ^^^^^^^^^^^^^^^^^^^^
47 |
48 |     def test_assert_in(self):
   |
help: Replace `assertLessEqual(...)` with `assert ...`
   |
45 |     def test_assert_less_equal(self):
   -         self.assertLessEqual(1, 2)  # Error
46 +         assert 1 <= 2  # Error
47 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertIn`
  --> PT009.py:49:9
   |
48 |     def test_assert_in(self):
49 |         self.assertIn(1, [2, 3])  # Error
   |         ^^^^^^^^^^^^^
50 |
51 |     def test_assert_not_in(self):
   |
help: Replace `assertIn(...)` with `assert ...`
   |
48 |     def test_assert_in(self):
   -         self.assertIn(1, [2, 3])  # Error
49 +         assert 1 in [2, 3]  # Error
50 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertNotIn`
  --> PT009.py:52:9
   |
51 |     def test_assert_not_in(self):
52 |         self.assertNotIn(2, [2, 3])  # Error
   |         ^^^^^^^^^^^^^^^^
53 |
54 |     def test_assert_is_none(self):
   |
help: Replace `assertNotIn(...)` with `assert ...`
   |
51 |     def test_assert_not_in(self):
   -         self.assertNotIn(2, [2, 3])  # Error
52 +         assert 2 not in [2, 3]  # Error
53 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertIsNone`
  --> PT009.py:55:9
   |
54 |     def test_assert_is_none(self):
55 |         self.assertIsNone(0)  # Error
   |         ^^^^^^^^^^^^^^^^^
56 |
57 |     def test_assert_is_not_none(self):
   |
help: Replace `assertIsNone(...)` with `assert ...`
   |
54 |     def test_assert_is_none(self):
   -         self.assertIsNone(0)  # Error
55 +         assert 0 is None  # Error
56 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertIsNotNone`
  --> PT009.py:58:9
   |
57 |     def test_assert_is_not_none(self):
58 |         self.assertIsNotNone(0)  # Error
   |         ^^^^^^^^^^^^^^^^^^^^
59 |
60 |     def test_assert_is(self):
   |
help: Replace `assertIsNotNone(...)` with `assert ...`
   |
57 |     def test_assert_is_not_none(self):
   -         self.assertIsNotNone(0)  # Error
58 +         assert 0 is not None  # Error
59 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertIs`
  --> PT009.py:61:9
   |
60 |     def test_assert_is(self):
61 |         self.assertIs([], [])  # Error
   |         ^^^^^^^^^^^^^
62 |
63 |     def test_assert_is_not(self):
   |
help: Replace `assertIs(...)` with `assert ...`
   |
60 |     def test_assert_is(self):
   -         self.assertIs([], [])  # Error
61 +         assert [] is []  # Error
62 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertIsNot`
  --> PT009.py:64:9
   |
63 |     def test_assert_is_not(self):
64 |         self.assertIsNot(1, 1)  # Error
   |         ^^^^^^^^^^^^^^^^
65 |
66 |     def test_assert_is_instance(self):
   |
help: Replace `assertIsNot(...)` with `assert ...`
   |
63 |     def test_assert_is_not(self):
   -         self.assertIsNot(1, 1)  # Error
64 +         assert 1 is not 1  # Error
65 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertIsInstance`
  --> PT009.py:67:9
   |
66 |     def test_assert_is_instance(self):
67 |         self.assertIsInstance(1, str)  # Error
   |         ^^^^^^^^^^^^^^^^^^^^^
68 |
69 |     def test_assert_is_not_instance(self):
   |
help: Replace `assertIsInstance(...)` with `assert ...`
   |
66 |     def test_assert_is_instance(self):
   -         self.assertIsInstance(1, str)  # Error
67 +         assert isinstance(1, str)  # Error
68 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertNotIsInstance`
  --> PT009.py:70:9
   |
69 |     def test_assert_is_not_instance(self):
70 |         self.assertNotIsInstance(1, int)  # Error
   |         ^^^^^^^^^^^^^^^^^^^^^^^^
71 |
72 |     def test_assert_regex(self):
   |
help: Replace `assertNotIsInstance(...)` with `assert ...`
   |
69 |     def test_assert_is_not_instance(self):
   -         self.assertNotIsInstance(1, int)  # Error
70 +         assert not isinstance(1, int)  # Error
71 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertRegex`
  --> PT009.py:73:9
   |
72 |     def test_assert_regex(self):
73 |         self.assertRegex("abc", r"def")  # Error
   |         ^^^^^^^^^^^^^^^^
74 |
75 |     def test_assert_not_regex(self):
   |
help: Replace `assertRegex(...)` with `assert ...`
   |
72 |     def test_assert_regex(self):
   -         self.assertRegex("abc", r"def")  # Error
73 +         assert re.search(r"def", "abc")  # Error
74 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertNotRegex`
  --> PT009.py:76:9
   |
75 |     def test_assert_not_regex(self):
76 |         self.assertNotRegex("abc", r"abc")  # Error
   |         ^^^^^^^^^^^^^^^^^^^
77 |
78 |     def test_assert_regexp_matches(self):
   |
help: Replace `assertNotRegex(...)` with `assert ...`
   |
75 |     def test_assert_not_regex(self):
   -         self.assertNotRegex("abc", r"abc")  # Error
76 +         assert not re.search(r"abc", "abc")  # Error
77 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertRegexpMatches`
  --> PT009.py:79:9
   |
78 |     def test_assert_regexp_matches(self):
79 |         self.assertRegexpMatches("abc", r"def")  # Error
   |         ^^^^^^^^^^^^^^^^^^^^^^^^
80 |
81 |     def test_assert_not_regexp_matches(self):
   |
help: Replace `assertRegexpMatches(...)` with `assert ...`
   |
78 |     def test_assert_regexp_matches(self):
   -         self.assertRegexpMatches("abc", r"def")  # Error
79 +         assert re.search(r"def", "abc")  # Error
80 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertNotRegex`
  --> PT009.py:82:9
   |
81 |     def test_assert_not_regexp_matches(self):
82 |         self.assertNotRegex("abc", r"abc")  # Error
   |         ^^^^^^^^^^^^^^^^^^^
83 |
84 |     def test_fail_if(self):
   |
help: Replace `assertNotRegex(...)` with `assert ...`
   |
81 |     def test_assert_not_regexp_matches(self):
   -         self.assertNotRegex("abc", r"abc")  # Error
82 +         assert not re.search(r"abc", "abc")  # Error
83 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `failIf`
  --> PT009.py:85:9
   |
84 |     def test_fail_if(self):
85 |         self.failIf("abc")  # Error
   |         ^^^^^^^^^^^
86 |
87 |     def test_fail_unless(self):
   |
help: Replace `failIf(...)` with `assert ...`
   |
84 |     def test_fail_if(self):
   -         self.failIf("abc")  # Error
85 +         assert not "abc"  # Error
86 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `failUnless`
  --> PT009.py:88:9
   |
87 |     def test_fail_unless(self):
88 |         self.failUnless("abc")  # Error
   |         ^^^^^^^^^^^^^^^
89 |
90 |     def test_fail_unless_equal(self):
   |
help: Replace `failUnless(...)` with `assert ...`
   |
87 |     def test_fail_unless(self):
   -         self.failUnless("abc")  # Error
88 +         assert "abc"  # Error
89 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `failUnlessEqual`
  --> PT009.py:91:9
   |
90 |     def test_fail_unless_equal(self):
91 |         self.failUnlessEqual(1, 2)  # Error
   |         ^^^^^^^^^^^^^^^^^^^^
92 |
93 |     def test_fail_if_equal(self):
   |
help: Replace `failUnlessEqual(...)` with `assert ...`
   |
90 |     def test_fail_unless_equal(self):
   -         self.failUnlessEqual(1, 2)  # Error
91 +         assert 1 == 2  # Error
92 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `failIfEqual`
  --> PT009.py:94:9
   |
93 |     def test_fail_if_equal(self):
94 |         self.failIfEqual(1, 2)  # Error
   |         ^^^^^^^^^^^^^^^^
   |
help: Replace `failIfEqual(...)` with `assert ...`
   |
93 |     def test_fail_if_equal(self):
   -         self.failIfEqual(1, 2)  # Error
94 +         assert 1 != 2  # Error
95 |
   |
note: This is an unsafe fix and may change runtime behavior

PT009 [*] Use a regular `assert` instead of unittest-style `assertTrue`
   --> PT009.py:98:2
    |
 97 | # Regression test for: https://github.com/astral-sh/ruff/issues/7455#issuecomment-1722459517
 98 | (self.assertTrue(
    |  ^^^^^^^^^^^^^^^
 99 |     "piAx_piAy_beta[r][x][y] = {17}".format(
100 |         self.model.piAx_piAy_beta[r][x][y])))
    |
help: Replace `assertTrue(...)` with `assert ...`
   |
97 | # Regression test for: https://github.com/astral-sh/ruff/issues/7455#issuecomment-1722459517
   - (self.assertTrue(
   -     "piAx_piAy_beta[r][x][y] = {17}".format(
   -         self.model.piAx_piAy_beta[r][x][y])))
98 + assert "piAx_piAy_beta[r][x][y] = {17}".format(self.model.piAx_piAy_beta[r][x][y])
   |
note: This is an unsafe fix and may change runtime behavior
