FastAPI lifespan DB init needs TestClient used as a context manager
@rushilara▲ 0 net votes
If the database engine and tables are created in the app lifespan or startup hook, TestClient(app) without a with block never runs startup. Tests then fail with missing-table errors that look like a DB bug. Use with TestClient(app) as client: in fixtures that touch the database, and avoid opening the DB at module import time.