From 323bb15c2fb9b063d2bdf388483ca88410435512 Mon Sep 17 00:00:00 2001 From: Oliver Sanders Date: Fri, 4 Sep 2020 09:57:12 +0100 Subject: [PATCH] tests: close asyncio tasks before closing the loop --- cylc/uiserver/conftest.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 cylc/uiserver/conftest.py diff --git a/cylc/uiserver/conftest.py b/cylc/uiserver/conftest.py new file mode 100644 index 00000000..22f7b25b --- /dev/null +++ b/cylc/uiserver/conftest.py @@ -0,0 +1,16 @@ +import asyncio + +import pytest + + +@pytest.fixture +def event_loop(): + """This fixture defines the event loop used for each test.""" + loop = asyncio.get_event_loop_policy().new_event_loop() + yield loop + # gracefully exit async generators + loop.run_until_complete(loop.shutdown_asyncgens()) + # cancel any tasks still running in this event loop + for task in asyncio.all_tasks(loop): + task.cancel() + loop.close()