-
-
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
Alternative approaches for PytestReturnNotNoneWarning
#10465
Comments
Seems reasonable. We are following |
I'd be in favor of keeping it as a warning too. While having tests return values something other than |
Making this an error would be problematic for Hy, which implements implicit returns, so e.g. a test that ends with a function call will pass on whatever the function returns, not |
This took me by surprise. I thought something was wrong in my codes. I would appreciate a simple option to silence these warnings for previously published codes. Better yet, the pytest team could be a little more considerate of their users by telling us that this was a new change that they introduced as of <version number@date>. |
To solve the issue this silly warning is causing I just wrap the
|
I feel this warning is overly opiniated, but a more constructive criticism is the warning prints the value of the return which in certain binary data cases can make bamboo logs unreadable due to text spam. It seems like it shouldn't print the value of the return because pytest is not prepared to properly format all possible return values. |
@jrounds this is primarily about helping people to avoid grave mistakes that are observable in the wild The typical case for those is devoid of other tools that help as its precisely for the aspiring test writer that is not yet up2date with all the surrounding best practise Im happy to discuss ways to make this easier for people that know what they are doing But it's going to be hard to just get me to agree on removing footgun safely for people that don't know or only think they know |
What footgun are we trying to protect against, though? Is the concern that users will return an expression instead of |
Beginners don't always fit what you believe ough to be |
Let me note that Python's unittest.py does the same too: python/cpython#85494 (I believe this was one of the original motivations for pytest to follow). As for:
I feel like an |
Where would you put the string |
Yes, it's a config option, see the configuration docs for details. You can also use |
I think we can settle then that this will never become an error then? If so, I think all we need to do is to change its superclass from pytest/src/_pytest/warning_types.py Line 59 in fd56968
|
👍 |
I've created a PR for this if it's still needed. |
- cf. pytest-dev/pytest#10465 - add pytest config - require pytest >= 7.2.0
Like others (here and here), I was surprised with the new warnings in pytest 7.2 when test functions return values other than
None
. Dating since the original issue (#7337), there was quite a bit of debate about whether this was a good idea.Personally, making something raise an exception not because it's an error, but simply because some users may get confused by it, feels somewhat inconsistent with other decisions made in Python. For example, these Python "gotchas" could raise exceptions, but don't, because sometimes you do actually mean to do these things -- as is the case with returning non-
None
from a test.I'd propose to (a) keep the warning, but leave it as a warning indefinitely (so
filterwarnings
can be used), and/or (b) add a config flag under thepytest-warnings
section for--allow-return-not-none
.The text was updated successfully, but these errors were encountered: