Add better warning msg for deprecated warns(None)

This commit is contained in:
Olga Matoula
2021-05-16 12:07:39 +01:00
parent 6ae71a2c2b
commit dbe66d97b4
3 changed files with 6 additions and 3 deletions

View File

@@ -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

View File

@@ -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: