How to run a test with specific event loop factories only
pytest_asyncio_loop_factories determines which named event loop factories are available for each test item.
By default, pytest-asyncio parametrizes a test with every factory returned for that item.
Use loop_factories to select a subset of the factory names returned by the hook.
Assume conftest.py provides two named factories:
import asyncio
class CustomEventLoop(asyncio.SelectorEventLoop):
pass
def pytest_asyncio_loop_factories(config, item):
return {
"default": asyncio.new_event_loop,
"custom": CustomEventLoop,
}
Then use loop_factories to select which available factory names a test should run with:
import pytest
@pytest.mark.asyncio
async def test_runs_with_every_configured_factory():
pass
@pytest.mark.asyncio(loop_factories=["custom"])
async def test_runs_with_only_custom_factory():
pass
If a requested factory name is not available from the hook, the test variant for that factory is skipped.
For declaring the factories themselves, see How to use custom event loop factories for tests.
For choosing the available factories from the pytest item, see How to configure event loop factories from the test item.