From a980ac08dd02e2aca935902a679dd46d41de720a Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Mon, 8 Aug 2022 10:23:26 +0100 Subject: [PATCH 1/7] make PytestReturnNotNoneWarning a RemovedIn8Warning by removing the `@final` decorator --- src/_pytest/compat.py | 6 ++++++ src/_pytest/warning_types.py | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py index d0cb07b2291..addb2ad1367 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -342,6 +342,12 @@ def final(f): return f +# TODO: sealed classes are not supported yet +# https://github.com/mypyc/mypyc/issues/846 +def sealed(f: _T) -> _T: + return f + + if sys.version_info >= (3, 8): from functools import cached_property as cached_property else: diff --git a/src/_pytest/warning_types.py b/src/_pytest/warning_types.py index c32ce80ccb1..1b11f0106ca 100644 --- a/src/_pytest/warning_types.py +++ b/src/_pytest/warning_types.py @@ -6,6 +6,7 @@ import attr from _pytest.compat import final +from _pytest.compat import sealed class PytestWarning(UserWarning): @@ -48,14 +49,15 @@ class PytestDeprecationWarning(PytestWarning, DeprecationWarning): __module__ = "pytest" -@final +@sealed class PytestRemovedIn8Warning(PytestDeprecationWarning): """Warning class for features that will be removed in pytest 8.""" __module__ = "pytest" -class PytestReturnNotNoneWarning(PytestDeprecationWarning): +@sealed +class PytestReturnNotNoneWarning(PytestRemovedIn8Warning): """Warning emitted when a test function is returning value other than None.""" __module__ = "pytest" From 7733e49436ba55f979ea7209d2e605856d94ac7e Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Sun, 9 Oct 2022 14:27:43 +0100 Subject: [PATCH 2/7] Update src/_pytest/warning_types.py --- src/_pytest/warning_types.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/_pytest/warning_types.py b/src/_pytest/warning_types.py index 1b11f0106ca..bb6c242bcc3 100644 --- a/src/_pytest/warning_types.py +++ b/src/_pytest/warning_types.py @@ -6,7 +6,6 @@ import attr from _pytest.compat import final -from _pytest.compat import sealed class PytestWarning(UserWarning): From c6dbb0aa85d02e03cb82661d2dce5ac05dd62708 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Sun, 9 Oct 2022 14:27:50 +0100 Subject: [PATCH 3/7] Update src/_pytest/warning_types.py --- src/_pytest/warning_types.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/_pytest/warning_types.py b/src/_pytest/warning_types.py index bb6c242bcc3..20f9d32566e 100644 --- a/src/_pytest/warning_types.py +++ b/src/_pytest/warning_types.py @@ -48,7 +48,6 @@ class PytestDeprecationWarning(PytestWarning, DeprecationWarning): __module__ = "pytest" -@sealed class PytestRemovedIn8Warning(PytestDeprecationWarning): """Warning class for features that will be removed in pytest 8.""" From ff4140b54a3b2ad6b33c555bb787ee120b00f9d4 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Sun, 9 Oct 2022 14:28:18 +0100 Subject: [PATCH 4/7] Update src/_pytest/warning_types.py --- src/_pytest/warning_types.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/_pytest/warning_types.py b/src/_pytest/warning_types.py index 20f9d32566e..817e2e40427 100644 --- a/src/_pytest/warning_types.py +++ b/src/_pytest/warning_types.py @@ -54,7 +54,6 @@ class PytestRemovedIn8Warning(PytestDeprecationWarning): __module__ = "pytest" -@sealed class PytestReturnNotNoneWarning(PytestRemovedIn8Warning): """Warning emitted when a test function is returning value other than None.""" From 59da17ddd26fabad3c611a96ec8258b2014d6d8b Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Sun, 9 Oct 2022 17:04:58 +0100 Subject: [PATCH 5/7] remove sealed from compat --- src/_pytest/compat.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/_pytest/compat.py b/src/_pytest/compat.py index addb2ad1367..d0cb07b2291 100644 --- a/src/_pytest/compat.py +++ b/src/_pytest/compat.py @@ -342,12 +342,6 @@ def final(f): return f -# TODO: sealed classes are not supported yet -# https://github.com/mypyc/mypyc/issues/846 -def sealed(f: _T) -> _T: - return f - - if sys.version_info >= (3, 8): from functools import cached_property as cached_property else: From 52ba1d164f315a50b1b4e32bcb28729b0b17593d Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Sun, 9 Oct 2022 17:07:13 +0100 Subject: [PATCH 6/7] Create 10196.trivial.rst --- changelog/10196.trivial.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/10196.trivial.rst diff --git a/changelog/10196.trivial.rst b/changelog/10196.trivial.rst new file mode 100644 index 00000000000..723dc3e0b06 --- /dev/null +++ b/changelog/10196.trivial.rst @@ -0,0 +1 @@ + make PytestReturnNotNoneWarning a RemovedIn8Warning From 2723e0d6fea451d455df9f59eb1f45e7882780f1 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sun, 9 Oct 2022 20:03:10 -0300 Subject: [PATCH 7/7] Improve changelog --- changelog/10196.trivial.rst | 2 +- doc/en/reference/reference.rst | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/changelog/10196.trivial.rst b/changelog/10196.trivial.rst index 723dc3e0b06..edf458f84c5 100644 --- a/changelog/10196.trivial.rst +++ b/changelog/10196.trivial.rst @@ -1 +1 @@ - make PytestReturnNotNoneWarning a RemovedIn8Warning +:class:`~pytest.PytestReturnNotNoneWarning` is now a subclass of :class:`~pytest.PytestRemovedIn8Warning`: the plan is to make returning non-``None`` from tests an error in the future. diff --git a/doc/en/reference/reference.rst b/doc/en/reference/reference.rst index bdad8fa597d..9e75890258f 100644 --- a/doc/en/reference/reference.rst +++ b/doc/en/reference/reference.rst @@ -1133,6 +1133,9 @@ Custom warnings generated in some situations such as improper usage or deprecate .. autoclass:: pytest.PytestReturnNotNoneWarning :show-inheritance: +.. autoclass:: pytest.PytestRemovedIn8Warning + :show-inheritance: + .. autoclass:: pytest.PytestUnhandledCoroutineWarning :show-inheritance: