Ejemplo
fastapi 0.141.1: Test a FastAPI app with TestClient and no network, and assert the validation error bodies it returns
Muestra verificada para pypi fastapi 0.141.1: Test a FastAPI app with TestClient and no network, and assert the validation error bodies it returns. El…
sha256:8bcaa6f98cea6edf681d2b0f76a18856106de62aab70009b1d22a5a50abb1257
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 2
- Claves de firma que lo compilaron
- 2
Entorno declarado
python 3.12 linux x64 python 3.12 python pip
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| python 3.12 · linux alpine/x64 · docker ed25519:a2ec939a4c60e243 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1 |
2026-08-14 |
| python 3.12 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1 |
2026-08-18 |
Caso
HOW- Objetivo
- Test a FastAPI app with TestClient and no network, and assert the validation error bodies it returns
- Símbolos
-
- fastapi.testclient.TestClient
- fastapi.HTTPException
- response_model
- lifespan
- pydantic.BaseModel
- httpx2.HTTPStatusError
- starlette.exceptions.StarletteDeprecationWarning
- Entorno
- python 3.12
- Creado
- 2026-08-14T08:53:22Z
Contrato
- assert TestClient targets http://testserver, so the run needs no socket, no port and no DNS
- assert TestClient drives the real ASGI pipeline, so pure ASGI middleware runs and stamps a header on the response
- assert calling the endpoint function directly does no coercion, so it returns nonsense instead of a 422
- assert an int path parameter given text answers 422 with detail[0].type int_parsing and loc path/item_id
- assert every 422 entry carries exactly type, loc, msg and input, and input echoes the submitted body back to the caller
- assert a missing body field answers 422 with type missing and loc body/age
- assert a valid body answers the declared 201 and response_model removes the extra field the handler returned
- assert an unexpected field in the request body is ignored by the model rather than rejected
- assert HTTPException(404) serialises to a single detail string
- assert the lifespan runs only when TestClient is entered as a context manager, so a plain client leaves startup unrun
- assert starlette 1.6 binds httpx2 for TestClient when both httpx2 and httpx are installed, so the response is not an httpx.Response
- assert raise_for_status on a TestClient response raises httpx2.HTTPStatusError, which except httpx.HTTPStatusError does not catch
- assert fastapi.testclient.TestClient is starlette's class re-exported unchanged
- assert hiding httpx2 makes the import fall back to httpx with a StarletteDeprecationWarning, which is a UserWarning and not a DeprecationWarning
Archivos
- csx.json
- requirements.txt
- src/__init__.py
- src/app.py
- test/contract.py