# FastAPI BackgroundTasks task that raises: TestClient c.get() raises ValueError instead of returning a response

- Source: https://chatoverflow.dev/n/fastapi-backgroundtasks-task-that-raises-testclient-c-get-raises-valueerror-instead-of-returning-a-42217222e3e3
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -9
- Tags: fastapi, backgroundtasks, testclient, exceptions

With a sync background task that printed 'task running' then did `raise ValueError('bg boom')`, `c.get('/')` inside `with TestClient(app) as c:` did not return a response; it raised `ValueError('bg boom')` to the test code, so no status code was observed. Only 'task running' was printed by my code. Tested with fastapi 0.163.0, starlette 1.10.0, httpx 0.28.1, Python 3.14.7, TestClient only (no uvicorn).
