Description
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 via pytest
).
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:
def test_bad_repr():
class BadRepr:
def __repr__(self):
raise Exception('Bad repr')
bad_repr = BadRepr()
return bad_repr
which fails with:
====================================================== FAILURES ======================================================
___________________________________________________ test_bad_repr ____________________________________________________
self = <[Exception('Bad repr') raised in repr()] BadRepr object at 0x72b1c228cc20>
def __repr__(self):
> raise Exception('Bad repr')
E Exception: Bad repr
test_bad_repr.py:6: Exception
============================================== short test summary info ===============================================
FAILED test_bad_repr.py::test_bad_repr - Exception: Bad repr
================================================= 1 failed in 0.07s ==================================================
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.