---
source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs
---
PT018 [*] Assertion should be broken down into multiple parts
  --> PT018.py:14:5
   |
13 | def test_error():
14 |     assert something and something_else
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15 |     assert something and something_else and something_third
16 |     assert something and not something_else
   |
help: Break down assertion into multiple parts
   |
13 | def test_error():
   -     assert something and something_else
14 +     assert something
15 +     assert something_else
16 |     assert something and something_else and something_third
   |
note: This is an unsafe fix and may change runtime behavior

PT018 [*] Assertion should be broken down into multiple parts
  --> PT018.py:15:5
   |
13 | def test_error():
14 |     assert something and something_else
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)
   |
help: Break down assertion into multiple parts
   |
14 |     assert something and something_else
   -     assert something and something_else and something_third
15 +     assert something and something_else
16 +     assert something_third
17 |     assert something and not something_else
   |
note: This is an unsafe fix and may change runtime behavior

PT018 [*] Assertion should be broken down into multiple parts
  --> PT018.py:16:5
   |
14 |     assert something and something_else
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)
18 |     assert not something and something_else
   |
help: Break down assertion into multiple parts
   |
15 |     assert something and something_else and something_third
   -     assert something and not something_else
16 +     assert something
17 +     assert not something_else
18 |     assert something and (something_else or something_third)
   |
note: This is an unsafe fix and may change runtime behavior

PT018 [*] Assertion should be broken down into multiple parts
  --> PT018.py:17:5
   |
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)
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18 |     assert not something and something_else
19 |     assert not (something or something_else)
   |
help: Break down assertion into multiple parts
   |
16 |     assert something and not something_else
   -     assert something and (something_else or something_third)
17 +     assert something
18 +     assert (something_else or something_third)
19 |     assert not something and something_else
   |
note: This is an unsafe fix and may change runtime behavior

PT018 [*] Assertion should be broken down into multiple parts
  --> PT018.py:18:5
   |
16 |     assert something and not something_else
17 |     assert something and (something_else or something_third)
18 |     assert not something and something_else
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19 |     assert not (something or something_else)
20 |     assert not (something or something_else or something_third)
   |
help: Break down assertion into multiple parts
   |
17 |     assert something and (something_else or something_third)
   -     assert not something and something_else
18 +     assert not something
19 +     assert something_else
20 |     assert not (something or something_else)
   |
note: This is an unsafe fix and may change runtime behavior

PT018 [*] Assertion should be broken down into multiple parts
  --> PT018.py:19:5
   |
17 |     assert something and (something_else or something_third)
18 |     assert not something and something_else
19 |     assert not (something or something_else)
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20 |     assert not (something or something_else or something_third)
21 |     assert something and something_else == """error
   |
help: Break down assertion into multiple parts
   |
18 |     assert not something and something_else
   -     assert not (something or something_else)
19 +     assert not something
20 +     assert not something_else
21 |     assert not (something or something_else or something_third)
   |
note: This is an unsafe fix and may change runtime behavior

PT018 [*] Assertion should be broken down into multiple parts
  --> PT018.py:20:5
   |
18 |     assert not something and something_else
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
   |
help: Break down assertion into multiple parts
   |
19 |     assert not (something or something_else)
   -     assert not (something or something_else or something_third)
20 +     assert not (something or something_else)
21 +     assert not something_third
22 |     assert something and something_else == """error
   |
note: This is an unsafe fix and may change runtime behavior

PT018 [*] Assertion should be broken down into multiple parts
  --> PT018.py:21:5
   |
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 | |     """
   | |_______^
24 |       assert (
25 |           something
   |
help: Break down assertion into multiple parts
   |
20 |     assert not (something or something_else or something_third)
   -     assert something and something_else == """error
21 +     assert something
22 +     assert something_else == """error
23 |     message
   |
note: This is an unsafe fix and may change runtime behavior

PT018 [*] Assertion should be broken down into multiple parts
  --> PT018.py:24:5
   |
22 |       message
23 |       """
24 | /     assert (
25 | |         something
26 | |         and something_else
27 | |         == """error
28 | | message
29 | | """
30 | |     )
   | |_____^
31 |
32 |       # recursive case
   |
help: Break down assertion into multiple parts
   |
23 |     """
24 +     assert something
25 |     assert (
   -         something
   -         and something_else
26 +         something_else
27 |         == """error
   |
note: This is an unsafe fix and may change runtime behavior

PT018 [*] Assertion should be broken down into multiple parts
  --> PT018.py:33:5
   |
32 |     # recursive case
33 |     assert not (a or not (b or c))
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34 |     assert not (a or not (b and c))
   |
help: Break down assertion into multiple parts
   |
32 |     # recursive case
   -     assert not (a or not (b or c))
33 +     assert not a
34 +     assert (b or c)
35 |     assert not (a or not (b and c))
   |
note: This is an unsafe fix and may change runtime behavior

PT018 [*] Assertion should be broken down into multiple parts
  --> PT018.py:34:5
   |
32 |     # recursive case
33 |     assert not (a or not (b or c))
34 |     assert not (a or not (b and c))
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
35 |
36 |     # detected, but no fix for messages
   |
help: Break down assertion into multiple parts
   |
33 |     assert not (a or not (b or c))
   -     assert not (a or not (b and c))
34 +     assert not a
35 +     assert (b and c)
36 |
   |
note: This is an unsafe fix and may change runtime behavior

PT018 Assertion should be broken down into multiple parts
  --> PT018.py:37:5
   |
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"
39 |     # detected, but no fix for mixed conditions (e.g. `a or b and c`)
   |
help: Break down assertion into multiple parts

PT018 Assertion should be broken down into multiple parts
  --> PT018.py:38:5
   |
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"
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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 Assertion should be broken down into multiple parts
  --> PT018.py:40:5
   |
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)
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Break down assertion into multiple parts

PT018 [*] Assertion should be broken down into multiple parts
  --> PT018.py:44:1
   |
43 | assert something  # OK
44 | assert something and something_else  # Error
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
45 | assert something and something_else and something_third  # Error
   |
help: Break down assertion into multiple parts
   |
43 | assert something  # OK
   - assert something and something_else  # Error
44 + assert something
45 + assert something_else
46 | assert something and something_else and something_third  # Error
   |
note: This is an unsafe fix and may change runtime behavior

PT018 [*] Assertion should be broken down into multiple parts
  --> PT018.py:45:1
   |
43 | assert something  # OK
44 | assert something and something_else  # Error
45 | assert something and something_else and something_third  # Error
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Break down assertion into multiple parts
   |
44 | assert something and something_else  # Error
   - assert something and something_else and something_third  # Error
45 + assert something and something_else
46 + assert something_third
47 |
   |
note: This is an unsafe fix and may change runtime behavior

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

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

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

PT018 [*] Assertion should be broken down into multiple parts
  --> PT018.py:59:5
   |
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 | |     )
   | |_____^
64 |
65 |       assert (not (
   |
help: Break down assertion into multiple parts
   |
61 |         or self.find_graph_input(node.input[0])
   -         or self.find_graph_output(node.input[0])
62 |     )
63 +     assert not (
64 +         self.find_graph_output(node.input[0])
65 +     )
66 |
   |
note: This is an unsafe fix and may change runtime behavior

PT018 [*] Assertion should be broken down into multiple parts
  --> PT018.py:65:5
   |
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 | |     ))
   | |______^
70 |
71 |       assert (not self.find_graph_output(node.output[0]) or
   |
help: Break down assertion into multiple parts
   |
64 |
   -     assert (not (
65 +     assert not (
66 |         self.find_graph_output(node.output[0])
67 |         or self.find_graph_input(node.input[0])
   -         or self.find_graph_output(node.input[0])
   -     ))
68 +     )
69 +     assert not (
70 +         self.find_graph_output(node.input[0])
71 +     )
72 |
   |
note: This is an unsafe fix and may change runtime behavior
