From fca243fa54ff4271604f02973c0bfe3df16bf9a7 Mon Sep 17 00:00:00 2001 From: Franco Grobler Date: Wed, 6 Dec 2023 16:02:20 +0200 Subject: [PATCH 1/2] Ensure loop is open --- pytest_asyncio/plugin.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pytest_asyncio/plugin.py b/pytest_asyncio/plugin.py index 934fb91c..3116fce2 100644 --- a/pytest_asyncio/plugin.py +++ b/pytest_asyncio/plugin.py @@ -322,6 +322,7 @@ async def setup(): def finalizer() -> None: """Yield again, to finalize.""" + nonlocal event_loop async def async_finalizer() -> None: try: @@ -333,6 +334,9 @@ async def async_finalizer() -> None: msg += "Yield only once." raise ValueError(msg) + if event_loop.is_closed(): + event_loop = asyncio.new_event_loop() + asyncio.set_event_loop(event_loop) event_loop.run_until_complete(async_finalizer()) result = event_loop.run_until_complete(setup()) From 4637c07315f2d785fb86a1368c6587f519840c31 Mon Sep 17 00:00:00 2001 From: Franco Grobler Date: Wed, 6 Dec 2023 16:26:28 +0200 Subject: [PATCH 2/2] Update git ignore to include mypy_cache --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 7dd9b771..bca72971 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] +*.mypy_cache # C extensions *.so @@ -67,3 +68,6 @@ target/ # generated by setuptools_scm pytest_asyncio/_version.py + +# JetBrains Run Configurations +.run