Skip to content

Commit 0e1132c

Browse files
committed
handle case when no event loop exists (support pytest-aiohttp)
1 parent 92b34e5 commit 0e1132c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pytest_asyncio/plugin.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,12 @@ async def setup():
129129
if kw not in request.keywords:
130130
continue
131131
policy = asyncio.get_event_loop_policy()
132-
old_loop = policy.get_event_loop()
132+
try:
133+
old_loop = policy.get_event_loop()
134+
except RuntimeError as exc:
135+
if 'no current event loop' not in str(exc):
136+
raise
137+
old_loop = None
133138
policy.set_event_loop(loop)
134139
fixturedef.addfinalizer(lambda: policy.set_event_loop(old_loop))
135140

0 commit comments

Comments
 (0)