Closed red-eight closed 4 years ago
Hi @red-eight,
Thanks for the report!
Indeed we should not try to skip async functions from TestCase
subclasses. I can verify that indeed on 5.3.5 things work as expected (added a failure to make sure):
λ pytest .tmp\test-async.py
======================== test session starts ========================
platform win32 -- Python 3.6.6, pytest-5.3.5.dev422+ga03e076e8.d20200303, py-1.8.1, collected 1 item
.tmp\test-async.py F [100%]
============================= FAILURES ==============================
______________ TestMyFunctions.test_my_async_function _______________
self = <test-async.TestMyFunctions testMethod=test_my_async_function>
async def test_my_async_function(self):
expected_value = 8
value = await my_async_function(4, 4)
> assert 0
E AssertionError: assert 0
.tmp\test-async.py:14: AssertionError
========================= 1 failed in 0.10s =========================
@nicoddemus i believe its related to #6927 but not entirely sure
there is an issue in our codebase wrt monkeypatching to work with unittest
It is related: #6927 explicitly adds support for IsolatedAsyncioTestCase
(py38+), but asynctest
doesn't have the same privilege so we issue a warning instead.
I'm currently investigating this; I think I have a bugfix for 5.4.X, and an enhancement for async functions in general for 6.0.0, should open a PR in a bit
For what it's worth, you still get this error if your unit test contains an errant yield
statement, turning it into an async generator instead of a coroutine. This case is not reported well.
If you're googling the error message, landing on this bug and wondering why it's affecting you even though you have python-asyncio
installed, check your test function for yield
statements.
Here's a simple test case:
Everything works using an older version of pytest (pytest-5.3.5).
For some reason, the test is skipped in newer versions of pytest.
Also, it seems like AioHTTPTestCase tests are NOT skipped.