pytest_twisted hides erroneous yield from non-deferred objects
jan-matejka opened this issue · 1 comments
jan-matejka commented
% cat a.py
from pytest_twisted import inlineCallbacks
def do_io():
return None # should return Deferred
@inlineCallbacks
def test_foo():
yield do_io()
% pytest ./a.py
============================================================================================================= test session starts =============================================================================================================
platform linux -- Python 3.7.3, pytest-4.6.3, py-1.8.0, pluggy-0.12.0
rootdir: /home/yac
plugins: twisted-1.10
collected 1 item
a.py . [100%]
========================================================================================================== 1 passed in 0.02 seconds ===========================================================================================================
graingert commented
This is the intended behaviour of a feature in twisted.
pytest_twisted.inlineCallbacks behaves exactly like:
https://twistedmatrix.com/documents/current/api/twisted.internet.defer.html#inlineCallbacks except it passes along the function signature so pytest can inject
Use an async def
and @pytest_twisted.ensureDeferred
if you want the modern, more explicit coroutine behaviour