---
source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs
snapshot_kind: text
---
PT018.py:14:5: PT018 [*] Assertion should be broken down into multiple parts
   |
13 | def test_error():
14 |     assert something and something_else
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
15 |     assert something and something_else and something_third
16 |     assert something and not something_else
   |
   = help: Break down assertion into multiple parts

ℹ Unsafe fix
11 11 | 
12 12 | 
13 13 | def test_error():
14    |-    assert something and something_else
   14 |+    assert something
   15 |+    assert something_else
15 16 |     assert something and something_else and something_third
16 17 |     assert something and not something_else
17 18 |     assert something and (something_else or something_third)

PT018.py:15:5: PT018 [*] Assertion should be broken down into multiple parts
   |
13 | def test_error():
14 |     assert something and something_else
15 |     assert something and something_else and something_third
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
16 |     assert something and not something_else
17 |     assert something and (something_else or something_third)
   |
   = help: Break down assertion into multiple parts

ℹ Unsafe fix
12 12 | 
13 13 | def test_error():
14 14 |     assert something and something_else
15    |-    assert something and something_else and something_third
   15 |+    assert something and something_else
   16 |+    assert something_third
16 17 |     assert something and not something_else
17 18 |     assert something and (something_else or something_third)
18 19 |     assert not something and something_else

PT018.py:16:5: PT018 [*] Assertion should be broken down into multiple parts
   |
14 |     assert something and something_else
15 |     assert something and something_else and something_third
16 |     assert something and not something_else
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
17 |     assert something and (something_else or something_third)
18 |     assert not something and something_else
   |
   = help: Break down assertion into multiple parts

ℹ Unsafe fix
13 13 | def test_error():
14 14 |     assert something and something_else
15 15 |     assert something and something_else and something_third
16    |-    assert something and not something_else
   16 |+    assert something
   17 |+    assert not something_else
17 18 |     assert something and (something_else or something_third)
18 19 |     assert not something and something_else
19 20 |     assert not (something or something_else)

PT018.py:17:5: PT018 [*] Assertion should be broken down into multiple parts
   |
15 |     assert something and something_else and something_third
16 |     assert something and not something_else
17 |     assert something and (something_else or something_third)
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
18 |     assert not something and something_else
19 |     assert not (something or something_else)
   |
   = help: Break down assertion into multiple parts

ℹ Unsafe fix
14 14 |     assert something and something_else
15 15 |     assert something and something_else and something_third
16 16 |     assert something and not something_else
17    |-    assert something and (something_else or something_third)
   17 |+    assert something
   18 |+    assert (something_else or something_third)
18 19 |     assert not something and something_else
19 20 |     assert not (something or something_else)
20 21 |     assert not (something or something_else or something_third)

PT018.py:18:5: PT018 [*] Assertion should be broken down into multiple parts
   |
16 |     assert something and not something_else
17 |     assert something and (something_else or something_third)
18 |     assert not something and something_else
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
19 |     assert not (something or something_else)
20 |     assert not (something or something_else or something_third)
   |
   = help: Break down assertion into multiple parts

ℹ Unsafe fix
15 15 |     assert something and something_else and something_third
16 16 |     assert something and not something_else
17 17 |     assert something and (something_else or something_third)
18    |-    assert not something and something_else
   18 |+    assert not something
   19 |+    assert something_else
19 20 |     assert not (something or something_else)
20 21 |     assert not (something or something_else or something_third)
21 22 |     assert something and something_else == """error

PT018.py:19:5: PT018 [*] Assertion should be broken down into multiple parts
   |
17 |     assert something and (something_else or something_third)
18 |     assert not something and something_else
19 |     assert not (something or something_else)
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
20 |     assert not (something or something_else or something_third)
21 |     assert something and something_else == """error
   |
   = help: Break down assertion into multiple parts

ℹ Unsafe fix
16 16 |     assert something and not something_else
17 17 |     assert something and (something_else or something_third)
18 18 |     assert not something and something_else
19    |-    assert not (something or something_else)
   19 |+    assert not something
   20 |+    assert not something_else
20 21 |     assert not (something or something_else or something_third)
21 22 |     assert something and something_else == """error
22 23 |     message

PT018.py:20:5: PT018 [*] Assertion should be broken down into multiple parts
   |
18 |     assert not something and something_else
19 |     assert not (something or something_else)
20 |     assert not (something or something_else or something_third)
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
21 |     assert something and something_else == """error
22 |     message
   |
   = help: Break down assertion into multiple parts

ℹ Unsafe fix
17 17 |     assert something and (something_else or something_third)
18 18 |     assert not something and something_else
19 19 |     assert not (something or something_else)
20    |-    assert not (something or something_else or something_third)
   20 |+    assert not (something or something_else)
   21 |+    assert not something_third
21 22 |     assert something and something_else == """error
22 23 |     message
23 24 |     """

PT018.py:21:5: PT018 [*] Assertion should be broken down into multiple parts
   |
19 |       assert not (something or something_else)
20 |       assert not (something or something_else or something_third)
21 |       assert something and something_else == """error
   |  _____^
22 | |     message
23 | |     """
   | |_______^ PT018
24 |       assert (
25 |           something
   |
   = help: Break down assertion into multiple parts

ℹ Unsafe fix
18 18 |     assert not something and something_else
19 19 |     assert not (something or something_else)
20 20 |     assert not (something or something_else or something_third)
21    |-    assert something and something_else == """error
   21 |+    assert something
   22 |+    assert something_else == """error
22 23 |     message
23 24 |     """
24 25 |     assert (

PT018.py:24:5: PT018 [*] Assertion should be broken down into multiple parts
   |
22 |       message
23 |       """
24 |       assert (
   |  _____^
25 | |         something
26 | |         and something_else
27 | |         == """error
28 | | message
29 | | """
30 | |     )
   | |_____^ PT018
31 |   
32 |       # recursive case
   |
   = help: Break down assertion into multiple parts

ℹ Unsafe fix
21 21 |     assert something and something_else == """error
22 22 |     message
23 23 |     """
   24 |+    assert something
24 25 |     assert (
25    |-        something
26    |-        and something_else
   26 |+        something_else
27 27 |         == """error
28 28 | message
29 29 | """

PT018.py:33:5: PT018 [*] Assertion should be broken down into multiple parts
   |
32 |     # recursive case
33 |     assert not (a or not (b or c))
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
34 |     assert not (a or not (b and c))
   |
   = help: Break down assertion into multiple parts

ℹ Unsafe fix
30 30 |     )
31 31 | 
32 32 |     # recursive case
33    |-    assert not (a or not (b or c))
   33 |+    assert not a
   34 |+    assert (b or c)
34 35 |     assert not (a or not (b and c))
35 36 | 
36 37 |     # detected, but no fix for messages

PT018.py:34:5: PT018 [*] Assertion should be broken down into multiple parts
   |
32 |     # recursive case
33 |     assert not (a or not (b or c))
34 |     assert not (a or not (b and c))
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
35 | 
36 |     # detected, but no fix for messages
   |
   = help: Break down assertion into multiple parts

ℹ Unsafe fix
31 31 | 
32 32 |     # recursive case
33 33 |     assert not (a or not (b or c))
34    |-    assert not (a or not (b and c))
   34 |+    assert not a
   35 |+    assert (b and c)
35 36 | 
36 37 |     # detected, but no fix for messages
37 38 |     assert something and something_else, "error message"

PT018.py:37:5: PT018 Assertion should be broken down into multiple parts
   |
36 |     # detected, but no fix for messages
37 |     assert something and something_else, "error message"
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
38 |     assert not (something or something_else and something_third), "with message"
39 |     # detected, but no fix for mixed conditions (e.g. `a or b and c`)
   |
   = help: Break down assertion into multiple parts

PT018.py:38:5: PT018 Assertion should be broken down into multiple parts
   |
36 |     # detected, but no fix for messages
37 |     assert something and something_else, "error message"
38 |     assert not (something or something_else and something_third), "with message"
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
39 |     # detected, but no fix for mixed conditions (e.g. `a or b and c`)
40 |     assert not (something or something_else and something_third)
   |
   = help: Break down assertion into multiple parts

PT018.py:40:5: PT018 Assertion should be broken down into multiple parts
   |
38 |     assert not (something or something_else and something_third), "with message"
39 |     # detected, but no fix for mixed conditions (e.g. `a or b and c`)
40 |     assert not (something or something_else and something_third)
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
   |
   = help: Break down assertion into multiple parts

PT018.py:44:1: PT018 [*] Assertion should be broken down into multiple parts
   |
43 | assert something  # OK
44 | assert something and something_else  # Error
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
45 | assert something and something_else and something_third  # Error
   |
   = help: Break down assertion into multiple parts

ℹ Unsafe fix
41 41 | 
42 42 | 
43 43 | assert something  # OK
44    |-assert something and something_else  # Error
   44 |+assert something
   45 |+assert something_else
45 46 | assert something and something_else and something_third  # Error
46 47 | 
47 48 | 

PT018.py:45:1: PT018 [*] Assertion should be broken down into multiple parts
   |
43 | assert something  # OK
44 | assert something and something_else  # Error
45 | assert something and something_else and something_third  # Error
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
   |
   = help: Break down assertion into multiple parts

ℹ Unsafe fix
42 42 | 
43 43 | assert something  # OK
44 44 | assert something and something_else  # Error
45    |-assert something and something_else and something_third  # Error
   45 |+assert something and something_else
   46 |+assert something_third
46 47 | 
47 48 | 
48 49 | def test_multiline():

PT018.py:49:5: PT018 Assertion should be broken down into multiple parts
   |
48 | def test_multiline():
49 |     assert something and something_else; x = 1
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
50 | 
51 |     x = 1; assert something and something_else
   |
   = help: Break down assertion into multiple parts

PT018.py:51:12: PT018 Assertion should be broken down into multiple parts
   |
49 |     assert something and something_else; x = 1
50 | 
51 |     x = 1; assert something and something_else
   |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
52 | 
53 |     x = 1; \
   |
   = help: Break down assertion into multiple parts

PT018.py:54:9: PT018 Assertion should be broken down into multiple parts
   |
53 |     x = 1; \
54 |         assert something and something_else
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018
   |
   = help: Break down assertion into multiple parts

PT018.py:59:5: PT018 [*] Assertion should be broken down into multiple parts
   |
57 |   # Regression test for: https://github.com/astral-sh/ruff/issues/7143
58 |   def test_parenthesized_not():
59 |       assert not (
   |  _____^
60 | |         self.find_graph_output(node.output[0])
61 | |         or self.find_graph_input(node.input[0])
62 | |         or self.find_graph_output(node.input[0])
63 | |     )
   | |_____^ PT018
64 |   
65 |       assert (not (
   |
   = help: Break down assertion into multiple parts

ℹ Unsafe fix
59 59 |     assert not (
60 60 |         self.find_graph_output(node.output[0])
61 61 |         or self.find_graph_input(node.input[0])
62    |-        or self.find_graph_output(node.input[0])
63 62 |     )
   63 |+    assert not (
   64 |+        self.find_graph_output(node.input[0])
   65 |+    )
64 66 | 
65 67 |     assert (not (
66 68 |         self.find_graph_output(node.output[0])

PT018.py:65:5: PT018 [*] Assertion should be broken down into multiple parts
   |
63 |       )
64 |   
65 |       assert (not (
   |  _____^
66 | |         self.find_graph_output(node.output[0])
67 | |         or self.find_graph_input(node.input[0])
68 | |         or self.find_graph_output(node.input[0])
69 | |     ))
   | |______^ PT018
70 |   
71 |       assert (not self.find_graph_output(node.output[0]) or
   |
   = help: Break down assertion into multiple parts

ℹ Unsafe fix
62 62 |         or self.find_graph_output(node.input[0])
63 63 |     )
64 64 | 
65    |-    assert (not (
   65 |+    assert not (
66 66 |         self.find_graph_output(node.output[0])
67 67 |         or self.find_graph_input(node.input[0])
68    |-        or self.find_graph_output(node.input[0])
69    |-    ))
   68 |+    )
   69 |+    assert not (
   70 |+        self.find_graph_output(node.input[0])
   71 |+    )
70 72 | 
71 73 |     assert (not self.find_graph_output(node.output[0]) or
72 74 |             self.find_graph_input(node.input[0]))
