Give warning when test function return other than None#9956
Give warning when test function return other than None#9956nicoddemus merged 16 commits intopytest-dev:mainfrom
Conversation
Zac-HD
left a comment
There was a problem hiding this comment.
Looks good to me - if you can confirm that this doesn't trigger when used with pytest-twisted, I'll be happy to merge 🥳
I saw there is a test file |
Without looking, I'd have gone and installed |
b6fdec5 to
ffad3f8
Compare
ffad3f8 to
03c1e51
Compare
|
Seems |
Zac-HD
left a comment
There was a problem hiding this comment.
Looks good to me! I'll give others a few days to review, but inclined to merge if I don't hear any objections.
Thanks for the patch, Cheuk 🤩
The-Compiler
left a comment
There was a problem hiding this comment.
Thanks @Cheukting, that seems quite useful! There's a bit of documentation and an addition to the public API missing - after that, this seems good to merge to me!
|
|
||
|
|
||
| @final | ||
| class PytestReturnNotNoneWarning(PytestDeprecationWarning): |
There was a problem hiding this comment.
This should be imported in src/pytest/__init__.py and added to __all__ there, since we want e.g. people to be able to ignore it via their config without having to import private API.
It should also be added to doc/en/reference/reference.rst with the other warnings, and probably get a new entry in doc/en/deprecations.rst.
There was a problem hiding this comment.
Thank you for the review, just want to be clear about the deprecations. Since we are already in 7, shall it be deprecated in 8? Or should I say 7?
There was a problem hiding this comment.
This should be a warning, not a deprecation warning
There was a problem hiding this comment.
Should it, if we plan to turn it into an error in the future?
There was a problem hiding this comment.
Deprecation warning is correct if we want to turn it into an error in the future, which seems the plan for unittest in the stdlib too: #7337 (comment).
Co-authored-by: Florian Bruhin <me@the-compiler.org>
1b589da to
bc2df82
Compare
bc2df82 to
a1f26dd
Compare
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
nicoddemus
left a comment
There was a problem hiding this comment.
Thanks a lot @Cheukting for the contribution! 👍
There was a problem hiding this comment.
I'm always a bit confused about how deprecations work in pytest - I feel like we should document this better somewhere... @nicoddemus @bluetech @RonnyPfannschmidt am I correct with my comment? Should PytestReturnNotNoneWarning really be its own class, or should it be an instance of PytestRemovedIn8Warning (or PytestRemovedIn9Warning even?) like some others in src/_pytest/deprecated.py?
Apologies for the delay and somewhat bumpy road @Cheukting!
|
It should be a normal warning The new class should be a subclass of user warning |
|
Also, good work, I'd love to get it in |
I disagree; IMO this should be a deprecation warning. I'd like to make it an error in future, and it seems like CPython is also going that way with a deprecation warning in python/cpython#27748 (for 3.11). |
|
in that case, lets go for Removed in pytest 8 |
Co-authored-by: Florian Bruhin <me@the-compiler.org>
The-Compiler
left a comment
There was a problem hiding this comment.
This seems ready now - @RonnyPfannschmidt @nicoddemus?
NotNoneWarning should subclass RemovedIn8Warning https://github.com/pytest-dev/pytest/pull/10012/files#diff-a7738833b05551853edda7933c165b6d7a41d521afb130fdc68631bd9129531eR59 |
It's not possible to subclass RemovedIn8Warning because it's decorated with |
…0196) As discussed in #9956 (comment). Also added PytestRemovedIn8Warning to the reference docs.
Adding a warning in
pytest_pyfunc_callafter theasync_warn_and_skipwill check if the return is something other thanNone.Closes #7337; see that issue for details.
CC @Zac-HD