diff --git a/tests/conftest.py b/tests/conftest.py index cd94089..37435ca 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,8 +6,16 @@ @pytest.fixture(scope="session") def event_loop(): - """Force the pytest-asyncio loop to be the main one.""" - loop = asyncio.get_event_loop() + """ + Force the pytest-asyncio loop to be the main one. + If there is no running event loop, create one and + set as the current one. + """ + try: + loop = asyncio.get_running_loop() + except RuntimeError: + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) yield loop