-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: close asyncio tasks before closing the loop
- Loading branch information
1 parent
020c11b
commit 323bb15
Showing
1 changed file
with
16 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |