From dbe66d97b49d94b131fa9ccbcf549f6376f88d9c Mon Sep 17 00:00:00 2001 From: Olga Matoula Date: Sun, 16 May 2021 12:07:39 +0100 Subject: [PATCH] Add better warning msg for deprecated warns(None) --- src/_pytest/deprecated.py | 3 ++- testing/deprecated_test.py | 5 +++-- testing/test_recwarn.py | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index 9f4b71bdc..99907d128 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -103,7 +103,8 @@ HOOK_LEGACY_PATH_ARG = UnformattedWarning( ) WARNS_NONE_ARG = PytestDeprecationWarning( - "Please pass an explicit Warning type or tuple of Warning types." + "Passing None to catch any warning has been deprecated, pass no arguments instead:\n" + " Replace pytest.warns(None) by simply pytest.warns()." ) # You want to make some `__init__` or function "private". diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index 86650877e..0974cf6c6 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -183,6 +183,7 @@ def test_hookproxy_warnings_for_fspath(tmp_path, hooktype, request): def test_warns_none_is_deprecated(): with pytest.warns( PytestDeprecationWarning, - match="Please pass an explicit Warning type or tuple of Warning types.", + match=r"Passing None to catch any warning has been deprecated, pass no arguments instead:\n Replace pytest.warns\(None\) by simply pytest.warns\(\).", ): - pytest.warns(None) + with pytest.warns(None): + pass diff --git a/testing/test_recwarn.py b/testing/test_recwarn.py index c73ab8a11..963f3aef2 100644 --- a/testing/test_recwarn.py +++ b/testing/test_recwarn.py @@ -307,6 +307,7 @@ class TestWarns: assert str(record[1].message) == "runtime" def test_record_only_none_deprecated_warn(self) -> None: + # This should become an error when WARNS_NONE_ARG is removed in Pytest 7.0 with warnings.catch_warnings(): warnings.simplefilter("ignore") with pytest.warns(None) as record: