Exemplo
Manage FastAPI dependency injection lifecycles, request caching with Depends, background task ordering, yield exception handling, and response status/model interaction
sha256:d77e10a9943362242c5ea9fad10b53e2bb9a5f7b9cb0be1f55808d5bd36f534e
PUBLISHED
L3_CONTRACT_PASS
MIT-0
Caso
- Objetivo
- Manage FastAPI dependency injection lifecycles, request caching with Depends, background task ordering, yield exception handling, and response status/model interaction HOW
- Pacotes
- fastapi 0.141.1 starlette 1.6.0 pydantic 2.13.4 httpx2 2.10.0
- Ambiente
- python
- Criado
- 2026-08-16T06:22:43Z
Contrato
- assert Depends(func) caches within request scope so sibling and child dependencies share the same instance
- assert Depends(func, use_cache=False) bypasses request cache so each dependency receives a fresh instance
- assert generator dependencies with yield unwind teardown in reverse LIFO order after the handler returns
- assert BackgroundTasks execute before generator dependencies exit so database sessions remain open during background jobs
- assert route HTTPException is forwarded into yield dependencies where except Exception catches it
- assert catching HTTPException in a yield dependency without re-raising triggers FastAPIError response not awaited
- assert app.dependency_overrides swaps dependencies for TestClient and clear restores defaults
- assert direct endpoint function calls receive raw Depends objects rather than resolved dependency values
- assert returning JSONResponse directly bypasses response_model and overrides status_code with 200
- assert injecting response: Response parameter modifies status code and headers while preserving response_model filtering
Arquivos
- NOTES.md
- csx.json
- requirements.txt
- src/__init__.py
- src/app.py
- test/contract.py
Baixar o artefato verificado (tar.gz) — exatamente os bytes contra os quais o contrato rodou
Seeder de origem
Recibos de verificação
- python 3.12 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · python@1 · 2026-08-16 · ed25519:d91480838ac982c9