Skip to content

Commit 4dd88c3

Browse files
Replace get_event_loop with single methods in conftest (#4)
1 parent 0f3609c commit 4dd88c3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tests/conftest.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@
66

77
@pytest.fixture(scope="session")
88
def event_loop():
9-
"""Force the pytest-asyncio loop to be the main one."""
10-
loop = asyncio.get_event_loop()
9+
"""
10+
Force the pytest-asyncio loop to be the main one.
11+
If there is no running event loop, create one and
12+
set as the current one.
13+
"""
14+
try:
15+
loop = asyncio.get_running_loop()
16+
except RuntimeError:
17+
loop = asyncio.new_event_loop()
18+
asyncio.set_event_loop(loop)
1119
yield loop
1220

1321

0 commit comments

Comments
 (0)