Skip to content

Commit 230ec35

Browse files
committed
test: bind the signal-handler fixture to the running loop
1 parent 005b9b6 commit 230ec35

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎tests/unit/test_signals.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,19 @@ def forced_exits(monkeypatch: pytest.MonkeyPatch) -> list[int]:
3535

3636

3737
@pytest.fixture
38-
def captured_handlers(monkeypatch: pytest.MonkeyPatch) -> dict[int, Any]:
39-
"""Capture the handlers the installer registers, on either platform."""
38+
async def captured_handlers(monkeypatch: pytest.MonkeyPatch) -> dict[int, Any]:
39+
"""Capture the handlers the installer registers, on either platform.
40+
41+
Async on purpose: the POSIX branch patches the *running* loop, which only
42+
exists inside the test's own loop.
43+
"""
4044
registered: dict[int, Any] = {}
4145

4246
if IS_WINDOWS:
4347
monkeypatch.setattr(signal, "getsignal", lambda sig: signal.SIG_DFL)
4448
monkeypatch.setattr(signal, "signal", lambda sig, handler: registered.setdefault(int(sig), handler))
4549
else:
46-
loop = asyncio.get_event_loop()
50+
loop = asyncio.get_running_loop()
4751
monkeypatch.setattr(
4852
loop,
4953
"add_signal_handler",

0 commit comments

Comments
 (0)