Closed
Description
Hi there,
I've migrated from 0.17.2 to 0.18.1 and activated auto asyncio_mode. It seems the mode is not able to apply asyncio marker to static methods.
The following minimized example:
class TestClass:
@staticmethod
async def test_static_method():
await asyncio.sleep(0)
Fails as follows:
$ pytest test_static_method.py
============================================================================ test session starts =============================================================================
platform win32 -- Python 3.8.5, pytest-6.1.2, py-1.9.0, pluggy-0.13.1
rootdir: D:\git\pytest-asyncio, configfile: pytest.ini
plugins: asyncio-0.18.1
asyncio: mode=auto
collected 1 item
test_static_method.py s [100%]
============================================================================== warnings summary ==============================================================================
test_static_method.py::TestClass::test_static_method
c:\users\kasyc\appdata\local\programs\python\python38\lib\site-packages\_pytest\python.py:173: PytestUnhandledCoroutineWarning: async def functions are not natively supporte
d and have been skipped.
You need to install a suitable plugin for your async framework, for example:
- anyio
- pytest-asyncio
- pytest-tornasync
- pytest-trio
- pytest-twisted
warnings.warn(PytestUnhandledCoroutineWarning(msg.format(nodeid)))
-- Docs: https://docs.pytest.org/en/stable/warnings.html
======================================================================= 1 skipped, 1 warning in 0.09s ========================================================================
test_auto_mode.py could easily be extended to cover that extra use case but I am not sure how to adapt pytest_pycollect_makeitem to fix the problem.
As a side note, with 0.17.2, we were doing our own auto mode with the following code and it was working for functions, methods and static methods:
def pytest_collection_modifyitems(items):
for item in items:
if isinstance(item, pytest.Function) and inspect.iscoroutinefunction(
item.function
):
item.add_marker("asyncio")
Metadata
Metadata
Assignees
Labels
No labels