pytest-patterns

Automate pytest-based unit and integration tests for Python FastAPI projects.

8|1|Updated Feb 3, 2026
One-click install
npx skills add https://github.com/hieutrtr/ai1-skills --skill pytest-patterns-hieutrtr
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytest-patterns
Source: https://github.com/hieutrtr/ai1-skills/tree/main/skills/pytest-patterns
Command: npx skills add https://github.com/hieutrtr/ai1-skills --skill pytest-patterns-hieutrtr

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides structured testing patterns for Python backend projects using pytest, enabling teams to write clear unit tests for services and repositories, robust integration tests with httpx.AsyncClient, and maintainable test infrastructure with fixtures and factory_boy.

Core Features & Use Cases

  • Unit testing patterns for services and repositories, including fixture organization and test structure.
  • Integration testing with httpx.AsyncClient for FastAPI endpoints, including realistic request/response simulations.
  • Factory and mocking strategies using factory_boy and pytest-mock to create repeatable test data and isolate logic.
  • Test organization and coverage guidelines covering tests/unit, tests/integration, conftest hierarchy, and coverage thresholds.

Quick Start

Install the required testing libraries (pytest, pytest-asyncio, httpx, factory_boy) and create tests under tests/unit and tests/integration. Run pytest to execute patterns and generate a coverage report.

Frequently Asked Questions about pytest-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure FastAPI pytest fixtures for unit and integration tests?

FastAPI pytest fixtures should be organized using a conftest hierarchy across tests/unit and tests/integration directories to isolate services and manage httpx.AsyncClient integration testing efficiently.

What is the best way to mock FastAPI services using factory_boy and pytest?

The best way to mock FastAPI services is applying factory_boy for repeatable test data generation and pytest-mock to isolate logic, ensuring strict mocking discipline across Python 3.12+ environments.

Does pytest-asyncio work with httpx.AsyncClient for FastAPI integration testing?

pytest-asyncio works seamlessly with httpx.AsyncClient to execute FastAPI integration testing, enabling realistic asynchronous request and response simulations for backend endpoints.

How do I enforce test organization and coverage thresholds in Python FastAPI projects?

To enforce test organization and coverage, structure tests into tests/unit and tests/integration folders with conftest.py hierarchies and apply coverage thresholds during pytest execution.

Can I use these pytest patterns for Python 3.12+ backend testing environments?

These pytest patterns are specifically designed for Python 3.12+ backend testing environments, applying structured unit and integration testing methodologies to FastAPI projects.

Why does my FastAPI integration test fail to isolate logic with pytest fixtures?

FastAPI integration tests fail to isolate logic when pytest fixtures lack proper organization, requiring factory_boy for data generation and pytest-mock to enforce strict mocking discipline.