Testing β Smoke-First, Contract-First
Everything openapi-first ships is tested against real specs, real handlers, and real HTTP through FastAPI's TestClient and the bundled templates. There are no fakes of the library itself.
π§ͺ 1. Suite Overview
Run with:
ποΈ 2. The Fixture Pattern
π§ͺ 3. What's Actually Asserted
3.1 App-level smoke
3.2 Fail-fast (the heart)
3.3 Loader validation
3.4 Client contract drift
ποΈ 4. Testing the Templates
Each bundled template ships its own test + in-memory store, so you get a runnable contract test the moment you scaffold:
test_crud_app.py / test_model_app.py / test_vet_app.py exercise the full CRUD surface through TestClient β including 201/204 status codes, 404s, and (in vet_app) SSE streaming via StreamingResponse.
πΉοΈ 5. Quality Gates (CI)
The same gates the library itself must pass are what keep the docs honest:
| Gate | Purpose |
|---|---|
black --check |
formatting parity |
ruff check |
lint hygiene |
mypy |
type safety (strict, --disable-error-code where intentional) |
pytest |
23 tests, green |
| coverage | tracked via pytest-cov (HTML + XML + term) |
Run the whole gate locally:
π‘ 6. Testing Tips
- Start from startup: assert
OpenAPIFirstApp(...)raises for the broken contracts β those are your most valuable tests - Client β server: smoke a client against the same spec the app was built from β one spec, two sides, zero drift
- Templates are scaffolds: their tests are copyable starting points, not canonical suites
- No mocking of the library: exercise loader β binder β app β client as a real pipeline