Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Py.Test add marker to all tests

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?

like image 548
Nick Humrich Avatar asked Jul 26 '16 15:07

Nick Humrich


1 Answers

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.

like image 108
The Compiler Avatar answered Oct 23 '22 14:10

The Compiler