---
source: crates/ruff_linter/src/rules/flake8_pytest_style/mod.rs
---
PT031.py:42:5: PT031 `pytest.warns()` block should contain a single simple statement
   |
41 |   def test_error_multiple_statements():
42 | /     with pytest.warns(UserWarning):
43 | |         foo()
44 | |         bar()
   | |_____________^ PT031
   |

PT031.py:48:5: PT031 `pytest.warns()` block should contain a single simple statement
   |
47 |   async def test_error_complex_statement():
48 | /     with pytest.warns(UserWarning):
49 | |         if True:
50 | |             foo()
   | |_________________^ PT031
51 |
52 |       with pytest.warns(UserWarning):
   |

PT031.py:52:5: PT031 `pytest.warns()` block should contain a single simple statement
   |
50 |               foo()
51 |
52 | /     with pytest.warns(UserWarning):
53 | |         for i in []:
54 | |             foo()
   | |_________________^ PT031
55 |
56 |       with pytest.warns(UserWarning):
   |

PT031.py:56:5: PT031 `pytest.warns()` block should contain a single simple statement
   |
54 |               foo()
55 |
56 | /     with pytest.warns(UserWarning):
57 | |         async for i in []:
58 | |             foo()
   | |_________________^ PT031
59 |
60 |       with pytest.warns(UserWarning):
   |

PT031.py:60:5: PT031 `pytest.warns()` block should contain a single simple statement
   |
58 |               foo()
59 |
60 | /     with pytest.warns(UserWarning):
61 | |         while True:
62 | |             foo()
   | |_________________^ PT031
63 |
64 |       with pytest.warns(UserWarning):
   |

PT031.py:64:5: PT031 `pytest.warns()` block should contain a single simple statement
   |
62 |               foo()
63 |
64 | /     with pytest.warns(UserWarning):
65 | |         async with context_manager_under_test():
66 | |             if True:
67 | |                 foo()
   | |_____________________^ PT031
   |

PT031.py:71:5: PT031 `pytest.warns()` block should contain a single simple statement
   |
70 |   def test_error_try():
71 | /     with pytest.warns(UserWarning):
72 | |         try:
73 | |             foo()
74 | |         except:
75 | |             raise
   | |_________________^ PT031
   |

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

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

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

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