Skip to content

Commit 8f536ba

Browse files
chore: simplify pytest-asyncio uvloop hook
Agent-Logs-Url: https://github.com/plugboard-dev/plugboard/sessions/1dcc6e9b-2a3e-46e1-9493-f1dd0572e763 Co-authored-by: toby-coleman <13170610+toby-coleman@users.noreply.github.com>
1 parent 25612da commit 8f536ba

2 files changed

Lines changed: 2 additions & 36 deletions

File tree

tests/conftest.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,12 @@
2121
from plugboard.utils.settings import Settings
2222

2323

24-
_HAS_LOOP_FACTORY_HOOK = hasattr(
25-
getattr(pytest_asyncio, "plugin", None),
26-
"PytestAsyncioSpecs",
27-
)
28-
29-
3024
@pytest.hookimpl(optionalhook=True)
31-
def pytest_asyncio_loop_factories(
32-
config: pytest.Config,
33-
item: pytest.Item,
34-
) -> dict[str, _t.Callable[[], asyncio.AbstractEventLoop]]:
25+
def pytest_asyncio_loop_factories() -> dict[str, _t.Callable[[], asyncio.AbstractEventLoop]]:
3526
"""Configure pytest-asyncio to create event loops with uvloop."""
36-
del config, item
3727
return {"uvloop": uvloop.new_event_loop}
3828

3929

40-
if not _HAS_LOOP_FACTORY_HOOK:
41-
42-
@pytest.fixture(scope="session")
43-
def event_loop_policy() -> uvloop.EventLoopPolicy:
44-
"""Fallback uvloop policy for pytest-asyncio versions without hook support."""
45-
return uvloop.EventLoopPolicy()
46-
47-
4830
@pytest.fixture(scope="session", autouse=True)
4931
def mp_set_start_method() -> None:
5032
"""Set the start method for multiprocessing to 'spawn'."""

tests/unit/test_conftest.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
11
"""Unit tests for the shared pytest configuration."""
22

3-
import typing as _t
4-
from unittest.mock import MagicMock
5-
6-
import pytest
73
import uvloop
84

95
from tests import conftest
106

117

128
def test_pytest_asyncio_loop_factories_uses_uvloop() -> None:
139
"""The shared pytest-asyncio hook should configure uvloop factories."""
14-
assert conftest.pytest_asyncio_loop_factories(
15-
MagicMock(spec=pytest.Config),
16-
MagicMock(spec=pytest.Item),
17-
) == {"uvloop": uvloop.new_event_loop}
18-
19-
20-
def test_event_loop_policy_fallback_uses_uvloop() -> None:
21-
"""Older pytest-asyncio releases should still get uvloop via the fallback fixture."""
22-
if conftest._HAS_LOOP_FACTORY_HOOK:
23-
pytest.skip("Installed pytest-asyncio already provides the loop-factory hook")
24-
25-
event_loop_policy = _t.cast(_t.Any, conftest.event_loop_policy)
26-
assert isinstance(event_loop_policy.__wrapped__(), uvloop.EventLoopPolicy)
10+
assert conftest.pytest_asyncio_loop_factories() == {"uvloop": uvloop.new_event_loop}

0 commit comments

Comments
 (0)