How to run all tests in the session in the same event loop
All tests can be run inside the same event loop by marking them with pytest.mark.asyncio(scope="session")
.
The easiest way to mark all tests is via a pytest_collection_modifyitems
hook in the conftest.py
at the root folder of your test suite.
import pytest
from pytest_asyncio import is_async_test
def pytest_collection_modifyitems(items):
pytest_asyncio_tests = (item for item in items if is_async_test(item))
session_scope_marker = pytest.mark.asyncio(scope="session")
for async_test in pytest_asyncio_tests:
async_test.add_marker(session_scope_marker, append=False)
Note that this will also override all manually applied marks in strict mode.