I am using python asyncio with pytest-aysncio, which means all my tests look like:
@pytest.mark.asyncio
async def test_my_func():
result = await my_func()
assert result == expected
Which works great, but I would prefer to not have to decorate every single function in order to get them to work. Is there a way in pytest to add this marker to every test function?
You could add a pytest_collection_modifyitems
hook to your conftest.py
:
def pytest_collection_modifyitems(items):
for item in items:
item.add_marker('asyncio')
Or to do so filewise, you can set pytestmark = pytest.mark.asyncio
globally in that file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With