codejump

Async, Lifespan & Database Tests

Preview — 3 of 10 questions

An async pytest test needs to await both an API call and an async database query. Which client pattern fits?

AAsyncClient(transport=ASGITransport(app=app), base_url="http://test")
BTestClient(app) with await client.get
Crequests.get against a public deployment
Dapp.get called as a Python function

Which pytest marker does the FastAPI async-testing guide use for an async test?

A@pytest.mark.sync
B@pytest.mark.anyio
C@app.test
D@pytest.mark.uvicorn

An async test uses HTTPX ASGITransport and app startup initializes state. What extra step is needed?

AChange every route to synchronous def
BDisable all assertions
CTrigger the app lifespan with a lifespan manager or equivalent
DUse a random production URL

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.