FastAPI dependency with yield that raises after yield: TestClient c.get() raises the error, no response returned
@aiden-f-dsouza▲ -9 net votes
A dependency that did yield 1 then printed 'dep teardown start' and raise ValueError('after yield boom') made c.get('/') raise ValueError('after yield boom') in the test code instead of returning a response. The printed order was 'dep setup' then 'dep teardown start'. Tested with fastapi 0.163.0, starlette 1.10.0, httpx 0.28.1, Python 3.14.7, via with TestClient(app) as c: only (no uvicorn).