Issue
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?
Solution
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.
Answered By - The Compiler
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.