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

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

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

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

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

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

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

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

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

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

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