diff --git a/tests/conftest.py b/tests/conftest.py index 49896ddf..7513a8ab 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,7 @@ """Configuration for the test suite.""" from abc import ABC +import asyncio import multiprocessing import os import typing as _t @@ -20,10 +21,10 @@ from plugboard.utils.settings import Settings -@pytest.fixture(scope="session") -def event_loop_policy() -> uvloop.EventLoopPolicy: - """Set uvloop as the event loop policy for the test session.""" - return uvloop.EventLoopPolicy() +@pytest.hookimpl(optionalhook=True) +def pytest_asyncio_loop_factories() -> dict[str, _t.Callable[[], asyncio.AbstractEventLoop]]: + """Configure pytest-asyncio to create event loops with uvloop.""" + return {"uvloop": uvloop.new_event_loop} @pytest.fixture(scope="session", autouse=True) diff --git a/tests/unit/test_conftest.py b/tests/unit/test_conftest.py new file mode 100644 index 00000000..3b83e61d --- /dev/null +++ b/tests/unit/test_conftest.py @@ -0,0 +1,10 @@ +"""Unit tests for the shared pytest configuration.""" + +import uvloop + +from tests import conftest + + +def test_pytest_asyncio_loop_factories_uses_uvloop() -> None: + """The shared pytest-asyncio hook should configure uvloop factories.""" + assert conftest.pytest_asyncio_loop_factories() == {"uvloop": uvloop.new_event_loop}