Skip to content

Commit 36b2269

Browse files
committed
[refactor] The synchronization wrapper for coroutine and async generator tests no longer requires an explicit event loop argument.
The wrapper retrieves the currently set loop via asyncio.get_event_loop, instead. Signed-off-by: Michael Seifert <[email protected]>
1 parent 5821031 commit 36b2269

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

pytest_asyncio/plugin.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
Set,
2222
TypeVar,
2323
Union,
24-
cast,
2524
overload,
2625
)
2726

@@ -509,19 +508,15 @@ def pytest_pyfunc_call(pyfuncitem: pytest.Function) -> Optional[object]:
509508
"""
510509
marker = pyfuncitem.get_closest_marker("asyncio")
511510
if marker is not None:
512-
funcargs: Dict[str, object] = pyfuncitem.funcargs # type: ignore[name-defined]
513-
loop = cast(asyncio.AbstractEventLoop, funcargs["event_loop"])
514511
if _is_hypothesis_test(pyfuncitem.obj):
515512
pyfuncitem.obj.hypothesis.inner_test = wrap_in_sync(
516513
pyfuncitem,
517514
pyfuncitem.obj.hypothesis.inner_test,
518-
_loop=loop,
519515
)
520516
else:
521517
pyfuncitem.obj = wrap_in_sync(
522518
pyfuncitem,
523519
pyfuncitem.obj,
524-
_loop=loop,
525520
)
526521
yield
527522

@@ -533,7 +528,6 @@ def _is_hypothesis_test(function: Any) -> bool:
533528
def wrap_in_sync(
534529
pyfuncitem: pytest.Function,
535530
func: Callable[..., Awaitable[Any]],
536-
_loop: asyncio.AbstractEventLoop,
537531
):
538532
"""Return a sync wrapper around an async function executing it in the
539533
current event loop."""
@@ -559,6 +553,7 @@ def inner(*args, **kwargs):
559553
)
560554
)
561555
return
556+
_loop = asyncio.get_event_loop()
562557
task = asyncio.ensure_future(coro, loop=_loop)
563558
try:
564559
_loop.run_until_complete(task)

0 commit comments

Comments
 (0)