---
source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs
---
PT012 `pytest.raises()` block should contain a single simple statement
  --> PT012.py:42:5
   |
41 |   def test_error_multiple_statements():
42 | /     with pytest.raises(AttributeError):
43 | |         len([])
44 | |         [].size
   | |_______________^
   |

PT012 `pytest.raises()` block should contain a single simple statement
  --> PT012.py:48:5
   |
47 |   async def test_error_complex_statement():
48 | /     with pytest.raises(AttributeError):
49 | |         if True:
50 | |             [].size
   | |___________________^
51 |
52 |       with pytest.raises(AttributeError):
   |

PT012 `pytest.raises()` block should contain a single simple statement
  --> PT012.py:52:5
   |
50 |               [].size
51 |
52 | /     with pytest.raises(AttributeError):
53 | |         for i in []:
54 | |             [].size
   | |___________________^
55 |
56 |       with pytest.raises(AttributeError):
   |

PT012 `pytest.raises()` block should contain a single simple statement
  --> PT012.py:56:5
   |
54 |               [].size
55 |
56 | /     with pytest.raises(AttributeError):
57 | |         async for i in []:
58 | |             [].size
   | |___________________^
59 |
60 |       with pytest.raises(AttributeError):
   |

PT012 `pytest.raises()` block should contain a single simple statement
  --> PT012.py:60:5
   |
58 |               [].size
59 |
60 | /     with pytest.raises(AttributeError):
61 | |         while True:
62 | |             [].size
   | |___________________^
63 |
64 |       with pytest.raises(AttributeError):
   |

PT012 `pytest.raises()` block should contain a single simple statement
  --> PT012.py:64:5
   |
62 |               [].size
63 |
64 | /     with pytest.raises(AttributeError):
65 | |         async with context_manager_under_test():
66 | |             if True:
67 | |                 raise Exception
   | |_______________________________^
   |

PT012 `pytest.raises()` block should contain a single simple statement
  --> PT012.py:71:5
   |
70 |   def test_error_try():
71 | /     with pytest.raises(AttributeError):
72 | |         try:
73 | |             [].size
74 | |         except:
75 | |             raise
   | |_________________^
   |

PT012 `pytest.raises()` block should contain a single simple statement
  --> PT012.py:83:5
   |
81 |       ## Errors
82 |
83 | /     with pytest.raises(RuntimeError):
84 | |         for a in b:
85 | |             print()
   | |___________________^
86 |
87 |       with pytest.raises(RuntimeError):
   |

PT012 `pytest.raises()` block should contain a single simple statement
  --> PT012.py:87:5
   |
85 |               print()
86 |
87 | /     with pytest.raises(RuntimeError):
88 | |         for a in b:
89 | |             assert foo
   | |______________________^
90 |
91 |       with pytest.raises(RuntimeError):
   |

PT012 `pytest.raises()` block should contain a single simple statement
  --> PT012.py:91:5
   |
89 |               assert foo
90 |
91 | /     with pytest.raises(RuntimeError):
92 | |         async for a in b:
93 | |             print()
   | |___________________^
94 |
95 |       with pytest.raises(RuntimeError):
   |

PT012 `pytest.raises()` block should contain a single simple statement
  --> PT012.py:95:5
   |
93 |               print()
94 |
95 | /     with pytest.raises(RuntimeError):
96 | |         async for a in b:
97 | |             assert foo
   | |______________________^
   |
