---
source: crates/ruff_linter/src/rules/ruff/mod.rs
---
RUF061 [*] Use context-manager form of `pytest.warns()`
  --> RUF061_warns.py:16:5
   |
15 | def test_error_trivial():
16 |     pytest.warns(UserWarning, raise_user_warning, "warning")
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Use `pytest.warns()` as a context-manager
   |
15 | def test_error_trivial():
   -     pytest.warns(UserWarning, raise_user_warning, "warning")
16 +     with pytest.warns(UserWarning):
17 +         raise_user_warning("warning")
18 |
   |
note: This is an unsafe fix and may change runtime behavior

RUF061 [*] Use context-manager form of `pytest.warns()`
  --> RUF061_warns.py:20:9
   |
19 | def test_error_assign():
20 |     s = pytest.warns(UserWarning, raise_user_warning, "warning")
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21 |     print(s)
   |
help: Use `pytest.warns()` as a context-manager
   |
19 | def test_error_assign():
   -     s = pytest.warns(UserWarning, raise_user_warning, "warning")
20 +     with pytest.warns(UserWarning):
21 +         s = raise_user_warning("warning")
22 |     print(s)
   |
note: This is an unsafe fix and may change runtime behavior

RUF061 [*] Use context-manager form of `pytest.warns()`
  --> RUF061_warns.py:25:5
   |
24 | def test_error_lambda():
25 |     pytest.warns(UserWarning, lambda: warnings.warn("", UserWarning))
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: Use `pytest.warns()` as a context-manager
   |
24 | def test_error_lambda():
   -     pytest.warns(UserWarning, lambda: warnings.warn("", UserWarning))
25 +     with pytest.warns(UserWarning):
26 +         (lambda: warnings.warn("", UserWarning))()
   |
note: This is an unsafe fix and may change runtime behavior
