Skip to content

Commit b2aef95

Browse files
committed
Ensure running event loop
1 parent 1ca0954 commit b2aef95

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tests/conftest.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@ def pytest_configure(config):
88
# https://twistedmatrix.com/trac/ticket/9766
99
# https://github.com/pytest-dev/pytest-twisted/issues/80
1010

11-
if config.getoption("reactor", "default") == "asyncio" and platform.system() == "Windows":
12-
import asyncio
11+
import asyncio
1312

13+
if config.getoption("reactor", "default") == "asyncio" and platform.system() == "Windows":
1414
selector_policy = asyncio.WindowsSelectorEventLoopPolicy()
1515
asyncio.set_event_loop_policy(selector_policy)
1616

17+
# Ensure there's a running event loop for the tests
18+
try:
19+
asyncio.get_running_loop()
20+
except RuntimeError:
21+
asyncio.set_event_loop(asyncio.new_event_loop())
22+
1723

1824
def pytest_sessionstart(session): # pylint: disable=unused-argument
1925
"""

0 commit comments

Comments
 (0)