Skip to content

Commit c0fd71d

Browse files
committed
Fix deprecated override of the event loop with async-solipsism
The new version of pytest-async doesn't allow overriding the event loop with a fixture as we used to, so we need to use the `event_loop_policy` fixture instead. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 25f1cc9 commit c0fd71d

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

tests/test_asyncio.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""Tests for the asyncio module."""
55

66
import asyncio
7-
from collections.abc import Iterator
87
from typing import Literal, assert_never
98

109
import async_solipsism
@@ -13,13 +12,11 @@
1312
from frequenz.core.asyncio import BackgroundService
1413

1514

16-
# Setting 'autouse' has no effect as this method replaces the event loop for all tests in the file.
17-
@pytest.fixture()
18-
def event_loop() -> Iterator[async_solipsism.EventLoop]:
19-
"""Replace the loop with one that doesn't interact with the outside world."""
20-
loop = async_solipsism.EventLoop()
21-
yield loop
22-
loop.close()
15+
# This method replaces the event loop for all tests in the file.
16+
@pytest.fixture
17+
def event_loop_policy() -> async_solipsism.EventLoopPolicy:
18+
"""Return an event loop policy that uses the async solipsism event loop."""
19+
return async_solipsism.EventLoopPolicy()
2320

2421

2522
class FakeService(BackgroundService):

0 commit comments

Comments
 (0)