File size: 551 Bytes
732b14f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""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)