Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path

import pytest
import pytest_asyncio
from cryptography.fernet import Fernet

os.environ.setdefault("DATABASE_URL", "sqlite+aiosqlite:///:memory:")
Expand All @@ -12,6 +13,24 @@
os.environ.setdefault("AUTH_COOKIE_ENABLED", "false")


@pytest_asyncio.fixture(scope="session", autouse=True)
async def _dispose_app_engine():
"""Dispose the global app engine before the session event loop closes.

Tests that exercise the real ``app.models.base.async_session_factory`` open
aiosqlite connections on the module-level ``engine`` that nothing else tears
down. With a session-scoped loop those connections' worker threads outlive
individual tests; when the loop finally closes, the daemon thread calls
``call_soon_threadsafe`` on it and pytest surfaces a
``PytestUnhandledThreadExceptionWarning: RuntimeError: Event loop is closed``.
Disposing here closes those connections while the loop is still running.
"""
yield
from app.models import base as base_mod

await base_mod.engine.dispose()


def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
"""Auto-apply 'unit' or 'integration' markers based on test file location."""
for item in items:
Expand Down
Loading