Skip to content

Commit dbe66d9

Browse files
committed
Add better warning msg for deprecated warns(None)
1 parent 6ae71a2 commit dbe66d9

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

src/_pytest/deprecated.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@
103103
)
104104

105105
WARNS_NONE_ARG = PytestDeprecationWarning(
106-
"Please pass an explicit Warning type or tuple of Warning types."
106+
"Passing None to catch any warning has been deprecated, pass no arguments instead:\n"
107+
" Replace pytest.warns(None) by simply pytest.warns()."
107108
)
108109

109110
# You want to make some `__init__` or function "private".

testing/deprecated_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ def test_hookproxy_warnings_for_fspath(tmp_path, hooktype, request):
183183
def test_warns_none_is_deprecated():
184184
with pytest.warns(
185185
PytestDeprecationWarning,
186-
match="Please pass an explicit Warning type or tuple of Warning types.",
186+
match=r"Passing None to catch any warning has been deprecated, pass no arguments instead:\n Replace pytest.warns\(None\) by simply pytest.warns\(\).",
187187
):
188-
pytest.warns(None)
188+
with pytest.warns(None):
189+
pass

testing/test_recwarn.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ def test_record_only(self) -> None:
307307
assert str(record[1].message) == "runtime"
308308

309309
def test_record_only_none_deprecated_warn(self) -> None:
310+
# This should become an error when WARNS_NONE_ARG is removed in Pytest 7.0
310311
with warnings.catch_warnings():
311312
warnings.simplefilter("ignore")
312313
with pytest.warns(None) as record:

0 commit comments

Comments
 (0)