Skip to content

Commit

Permalink
tests: close asyncio tasks before closing the loop
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-sanders committed Sep 4, 2020
1 parent 020c11b commit 323bb15
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cylc/uiserver/conftest.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 323bb15

Please sign in to comment.