Skip to content

Commit 7855fde

Browse files
committed
update changelog, warning msg and warning inherit
1 parent 238a5ca commit 7855fde

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

changelog/7337.improvement.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Warns for test functions that return non-None. Now in `pytest_pyfunc_call` after the `async_warn_and_skip` it will check for if the return is something other than None.
1+
Warns for test functions that return non-None.

src/_pytest/python.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,8 @@ def pytest_pyfunc_call(pyfuncitem: "Function") -> Optional[object]:
197197
elif result is not None:
198198
warnings.warn(
199199
PytestReturnNotNoneWarning(
200-
"Test function returning {result}, do you mean to use `assert` instead or `return`?".format(
201-
result=result
202-
)
200+
f"Expected None, but the test returned {result!r}, which will be an error in a "
201+
"future version of Pytest. Did you mean to use `assert` instead of `return`?"
203202
)
204203
)
205204
return True

src/_pytest/warning_types.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ class PytestCollectionWarning(PytestWarning):
4242
__module__ = "pytest"
4343

4444

45-
@final
46-
class PytestReturnNotNoneWarning(PytestWarning):
47-
"""Warning emitted when a test function is returning value other than None."""
48-
49-
__module__ = "pytest"
50-
51-
5245
class PytestDeprecationWarning(PytestWarning, DeprecationWarning):
5346
"""Warning class for features that will be removed in a future version."""
5447

@@ -62,6 +55,13 @@ class PytestRemovedIn8Warning(PytestDeprecationWarning):
6255
__module__ = "pytest"
6356

6457

58+
@final
59+
class PytestReturnNotNoneWarning(PytestDeprecationWarning):
60+
"""Warning emitted when a test function is returning value other than None."""
61+
62+
__module__ = "pytest"
63+
64+
6565
@final
6666
class PytestExperimentalApiWarning(PytestWarning, FutureWarning):
6767
"""Warning category used to denote experiments in pytest.

0 commit comments

Comments
 (0)