-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Undocumented removal of PytestReturnNotNoneWarning
#13477
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
Comments
This is a regression the warning needs to return |
This has affected networkx as well: networkx/networkx#8090 In networkx's case specifically, it's a bad interaction between the pytest-mpl plugin and the pytest policy that tests must not return. The pytest-mpl |
Hi folks, I agree that the current state is unfortunate. I think we should keep the warning indefinitely (not as a deprecation). However, I don't think we need an explicit option to suppress it, seems like using |
When returning the warning it should have a new message, and the deprecation docs should mention that it's not deprecated. This was the previous message PytestReturnNotNoneWarning(
f"Expected None, but {pyfuncitem.nodeid} returned {result!r}, which will be an error in a "
"future version of pytest. Did you mean to use `assert` instead of `return`?"
) and I think we want coroutines to stay as an error, so the logic will be something like:
This kind of makes me think that a config option might be a neater way of allowing non-None return values, especially as there may be newbies that don't run with In a perfect world I think there may be even better ways of achieving things instead of returning values, but /shrug |
Yup The none warning is forever |
Very happy with the plan to revert back to the warning and remove the deprecation notice! For the warning/error message, maybe something like this would make it more robust in case the repr is very long or raises an exception? PytestReturnNotNoneWarning(
f"Tests are expected to return `None`, but {pyfuncitem.nodeid} returned {type(result)}."
"Did you mean to use `assert` instead of `return`?"
) If this warning is targeted at newbie users, could make it even more explicit: PytestReturnNotNoneWarning(
f"Test outputs are not checked so tests are expected to return `None`, "
"but {pyfuncitem.nodeid} returned {type(result)}. "
"Did you mean to use `assert` instead of `return`?"
) |
Add constraint for sqlalchemy-spanner and pytest Context: - googleapis/python-spanner-sqlalchemy#682 - pytest-dev/pytest#13477 Failed build: https://fusion2.corp.google.com/ci/kokoro/prod:composer%2Fairflow%2F2_10_5%2Fdependencies/activity/9a63fe2e-3480-4e38-b981-f445bd7b3b37/log Change-Id: Icdb2aeb1848b1fb1d23a23ec4fa0f59ee47d9d4a GitOrigin-RevId: 2aba72736d1a45d2aa2775c554b1ab11824b5431
Since this warning is meant to be permanent, added proper documentation to the `assert` section in the docs. Fixes pytest-dev#13477
Opened #13495. 👍 |
Since this warning is meant to be permanent, added proper documentation to the `assert` section in the docs. Fixes pytest-dev#13477
It looks like #12346 got merged without reference to some of the previous discussions, e.g. #10465.
With
pytest
8.4, this change causes workflows to fail if they return non-None
values (which can be useful for debugging interactively by running the file directly as well as viapytest
).At minimum, the deprecation documentation does not say that this feature was removed:
https://docs.pytest.org/en/stable/deprecations.html#returning-non-none-value-in-test-functions
However, other users mentioned other issues with the current implementation as well, e.g. trying to print the full return value can cause problems with large objects or binary data (see example below).
In terms of a solution, I would like to ask that there be a config option to skip this (similar to
--doctest-ignore-import-errors
). I agree that newbie users should be protected from this gotcha -- but I don't think that means this feature should be forcibly removed for everyone!Here's an example of a test that causes an implicit
pytest
error as it tries to print the object being returned:which fails with:
This is a pretty confusing failure, as at no point is it clear from the error why the object repr is being called in the first place, and this error is raised instead of the return-not-None test failure.
The text was updated successfully, but these errors were encountered: