fix deprecated pytest async warning
- Cleanup pending async tasks - fix deprecated warning about event_loop
This commit is contained in:
20
app/tests/conftest.py
Normal file
20
app/tests/conftest.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import pytest_asyncio
|
||||
import asyncio
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def my_loop():
|
||||
event_loop = asyncio.get_running_loop()
|
||||
yield event_loop
|
||||
|
||||
# Collect all tasks and cancel those that are not 'done'.
|
||||
tasks = asyncio.all_tasks(event_loop)
|
||||
tasks = [t for t in tasks if not t.done()]
|
||||
for task in tasks:
|
||||
task.cancel()
|
||||
|
||||
# Wait for all tasks to complete, ignoring any CancelledErrors
|
||||
try:
|
||||
await asyncio.wait(tasks)
|
||||
except asyncio.exceptions.CancelledError:
|
||||
pass
|
||||
Reference in New Issue
Block a user