"""Background task registry.""" from __future__ import annotations import asyncio import pytest from app.api.background_tasks import spawn_background_task @pytest.mark.asyncio async def test_spawn_background_task_logs_unhandled_exception(caplog) -> None: import logging caplog.set_level(logging.ERROR) async def _boom() -> None: raise RuntimeError("task failed") spawn_background_task(_boom()) await asyncio.sleep(0.05) assert any("Unhandled exception in background task" in r.message for r in caplog.records)