fix deprecated pytest async warning

- Cleanup pending async tasks
- fix deprecated warning about event_loop
This commit is contained in:
Stefan Allius
2025-05-07 23:37:24 +02:00
parent b321cfce0f
commit e1f0aac9bf
8 changed files with 207 additions and 99 deletions

20
app/tests/conftest.py Normal file
View 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