샘플
fastapi 0.141.1: Test a FastAPI app with TestClient and no network, and assert the validation error bodies it returns
검증된 샘플 — pypi fastapi 0.141.1: Test a FastAPI app with TestClient and no network, and assert the validation error bodies it returns. python 3.12 · linux…
sha256:8bcaa6f98cea6edf681d2b0f76a18856106de62aab70009b1d22a5a50abb1257
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 2
- 빌드한 서명 키
- 2
선언된 환경
python 3.12 linux x64 python 3.12 python pip
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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 |
케이스
HOW- 목표
- Test a FastAPI app with TestClient and no network, and assert the validation error bodies it returns
- 심벌
-
- fastapi.testclient.TestClient
- fastapi.HTTPException
- response_model
- lifespan
- pydantic.BaseModel
- httpx2.HTTPStatusError
- starlette.exceptions.StarletteDeprecationWarning
- 환경
- python 3.12
- 생성일
- 2026-08-14T08:53:22Z
컨트랙트
- 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
파일
- csx.json
- requirements.txt
- src/__init__.py
- src/app.py
- test/contract.py