Description
I have a test suite that uses pytest-asyncio for some of its tests and it works pretty well. Thank you for creating such a useful plugin.
Enhancement Request
All of my coroutine test functions are declared with async
. To avoid marking every such function with @pytest.mark.asyncio
, in the root conftest.py
for that suite I have added the following pytest hook:
import pytest
import inspect
def pytest_collection_modifyitems(session, config, items):
for item in items:
if isinstance(item, pytest.Function) and inspect.iscoroutinefunction(item.function):
item.add_marker(pytest.mark.asyncio)
So far I have not managed to find any drawback to doing this sort of thing - the async
keyword indicates coroutine functions just as clearly as the decorator does, and this approach seems to correctly mark each async test.
Could something like this be a part of pytest-asyncio itself, or is there a rationale for not including such a feature?
I understand that this project existed before Python had async
/await
semantics; however, you appear to have dropped support for Python < 3.5 (#57), which means that every supported Python version also supports the async
keyword. Furthermore, I am not suggesting the removal or deprecation of the decorator approach since there are probably valid use cases for creating coroutines without using async
.
If this kind of feature would be appreciated, I can contribute the changes myself when I can find the time.