-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Give warning when test function return other than None #9956
Give warning when test function return other than None #9956
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 🤩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!
@@ -55,6 +55,13 @@ class PytestRemovedIn8Warning(PytestDeprecationWarning): | |||
__module__ = "pytest" | |||
|
|||
|
|||
@final | |||
class PytestReturnNotNoneWarning(PytestDeprecationWarning): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a warning, not a deprecation warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it, if we plan to turn it into an error in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
1b589da
to
bc2df82
Compare
bc2df82
to
a1f26dd
Compare
Co-authored-by: Bruno Oliveira <[email protected]>
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @Cheukting for the contribution! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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_call
after theasync_warn_and_skip
will check if the return is something other thanNone
.Closes #7337; see that issue for details.
CC @Zac-HD