pytest-patterns

Apply pytest fixture patterns, parametrization, and mocking to Python test suites.

1|Updated Nov 18, 2025
One-click install
npx skills add https://github.com/manutej/crush-mcp-server --skill pytest-patterns-manutej
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytest-patterns
Source: https://github.com/manutej/crush-mcp-server/tree/main/.claude/skills/pytest-patterns
Command: npx skills add https://github.com/manutej/crush-mcp-server --skill pytest-patterns-manutej

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides patterns for pytest fixtures, including scopes, dependencies, factories, and complex compositions to build reliable, maintainable test suites.

Core Features & Use Cases

  • Fixtures & Scopes: Function, module, class, and session scopes for efficient tests.
  • Fixture Dependencies: Compose fixtures to share setup, with proper teardown.
  • Test Organization: Structure large test suites for readability and reliability.

Quick Start

Create a set of fixtures with varied scopes and demonstrate them in a small test module.

Frequently Asked Questions about pytest-patterns

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

FAQPage Schema
How do I structure pytest fixtures with different scopes for efficient testing?

Pytest fixture scopes—function, module, class, and session—control setup and teardown timing. Function scope runs per test, module scope shares setup across a file, class scope applies to test classes, and session scope persists across your entire test run, reducing redundant initialization.

What's the best way to compose fixtures with dependencies in pytest?

Fixture dependencies let you build complex test setups by having fixtures accept other fixtures as parameters. Pytest automatically injects them in the correct order, manages teardown, and ensures proper resource cleanup across your test suite.

How do I organize large Python test suites for reliability and readability?

Organize tests using pytest fixture factories, parametrization, and layered scopes to separate concerns. Group related tests, reuse fixtures across modules, and apply consistent patterns for unit, integration, API, and end-to-end tests to maintain clarity as your suite grows.

Can I use pytest fixtures with async code and external services?

Yes. Pytest fixtures support async setup and teardown, and fixture patterns handle external service mocking and dependencies. Structure async fixtures with proper scoping and composition to test async functions, API calls, and dependent services reliably.

Why should I use fixture factories instead of simple fixtures in pytest?

Fixture factories generate multiple test instances dynamically, letting you parametrize complex setups without duplication. They're essential when you need variations of the same resource—different database states, API clients, or mock objects—across many tests.

How do pytest fixture patterns support CI/CD readiness?

Structured fixtures with proper scopes, mocking of external services, and organized test categorization ensure tests run reliably in CI environments. This pattern foundation enables parallel execution, deterministic results, and coverage analysis across your test pipeline.