pytest-fastapi-pattern

Community

Write production-grade FastAPI integration tests

Authorsaintgo7
Version1.0.0
Installs0

System Documentation

What problem does it solve?

FastAPI integration tests often fail or give misleading results when sync TestClient usage skips lifespan startup, database state leaks across tests, and upstream HTTP calls to vLLM/OpenAI are not properly mocked.

Core Features & Use Cases

  • In-process async client with real lifespan: Uses httpx AsyncClient with ASGITransport (lifespan enabled) so startup/shutdown code runs exactly like production.
  • Deterministic, isolated DB state: Uses in-memory SQLite with StaticPool plus a per-test create_all/drop_all flow to prevent cross-test contamination.
  • Upstream-safe mocking for LLM gateways: Uses respx to mock upstream HTTP calls (e.g., vLLM/OpenAI) and ensures mocks are actually exercised.
  • Streaming SSE validation: Verifies streaming outputs at the chunk/byte level using async streaming iteration and SSE markers like [DONE].

Quick Start

Ask to generate a FastAPI pytest integration test setup using httpx ASGITransport with lifespan enabled, an autouse-style DB reset fixture, respx upstream mocking, and SSE chunk assertions for streaming endpoints.

Dependency Matrix

Required Modules

None required

Components

references

💻 Claude Code Installation

Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.

Please help me install this Skill:
Name: pytest-fastapi-pattern
Download link: https://github.com/saintgo7/claude-skills/archive/main.zip#pytest-fastapi-pattern

Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
View Source Repository

Agent Skills Search Helper

Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.