Skip to content

Commit 94f6106

Browse files
tjkusonseifertm
authored andcommitted
test: Added tests which assert that the event loop is reinstated if unset by a test.
1 parent df61991 commit 94f6106

File tree

3 files changed

+376
-5
lines changed

3 files changed

+376
-5
lines changed

changelog.d/1177.fixed.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``RuntimeError: There is no current event loop in thread 'MainThread'`` when any test unsets the event loop (such as when using ``asyncio.run`` and ``asyncio.Runner``).

pytest_asyncio/plugin.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def _asyncgen_fixture_wrapper(
311311
gen_obj = fixture_function(*args, **kwargs)
312312

313313
async def setup():
314-
res = await gen_obj.__anext__() # type: ignore[union-attr]
314+
res = await gen_obj.__anext__()
315315
return res
316316

317317
context = contextvars.copy_context()
@@ -324,7 +324,7 @@ def finalizer() -> None:
324324

325325
async def async_finalizer() -> None:
326326
try:
327-
await gen_obj.__anext__() # type: ignore[union-attr]
327+
await gen_obj.__anext__()
328328
except StopAsyncIteration:
329329
pass
330330
else:
@@ -353,8 +353,7 @@ def _wrap_async_fixture(
353353
runner: Runner,
354354
request: FixtureRequest,
355355
) -> Callable[AsyncFixtureParams, AsyncFixtureReturnType]:
356-
357-
@functools.wraps(fixture_function) # type: ignore[arg-type]
356+
@functools.wraps(fixture_function)
358357
def _async_fixture_wrapper(
359358
*args: AsyncFixtureParams.args,
360359
**kwargs: AsyncFixtureParams.kwargs,
@@ -782,7 +781,7 @@ def _get_marked_loop_scope(
782781
return scope
783782

784783

785-
def _get_default_test_loop_scope(config: Config) -> _ScopeName:
784+
def _get_default_test_loop_scope(config: Config) -> Any:
786785
return config.getini("asyncio_default_test_loop_scope")
787786

788787

0 commit comments

Comments
 (0)