Skip to content

Commit dafef6c

Browse files
committed
refactor: Extracted a function to mark an event loop as created by pytest-asyncio.
1 parent 0c931b7 commit dafef6c

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pytest_asyncio/plugin.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,7 @@ def scoped_event_loop(
709709
) -> Iterator[asyncio.AbstractEventLoop]:
710710
new_loop_policy = event_loop_policy
711711
with _temporary_event_loop_policy(new_loop_policy):
712-
loop = asyncio.new_event_loop()
713-
loop.__pytest_asyncio = True # type: ignore[attr-defined]
712+
loop = _make_pytest_asyncio_loop(asyncio.new_event_loop())
714713
asyncio.set_event_loop(loop)
715714
yield loop
716715
loop.close()
@@ -885,6 +884,11 @@ def pytest_fixture_setup(
885884
yield
886885

887886

887+
def _make_pytest_asyncio_loop(loop: AbstractEventLoop) -> AbstractEventLoop:
888+
loop.__pytest_asyncio = True # type: ignore[attr-defined]
889+
return loop
890+
891+
888892
def _is_pytest_asyncio_loop(loop: AbstractEventLoop) -> bool:
889893
return getattr(loop, "__pytest_asyncio", False)
890894

@@ -1161,8 +1165,7 @@ def _session_event_loop(
11611165
) -> Iterator[asyncio.AbstractEventLoop]:
11621166
new_loop_policy = event_loop_policy
11631167
with _temporary_event_loop_policy(new_loop_policy):
1164-
loop = asyncio.new_event_loop()
1165-
loop.__pytest_asyncio = True # type: ignore[attr-defined]
1168+
loop = _make_pytest_asyncio_loop(asyncio.new_event_loop())
11661169
asyncio.set_event_loop(loop)
11671170
yield loop
11681171
loop.close()

0 commit comments

Comments
 (0)