python-pytest-patterns

Apply pytest patterns for fixtures, parameterization, mocking, and async testing.

29|6|Updated Nov 27, 2025
One-click install
npx skills add https://github.com/0xDarkMatter/claude-mods --skill python-pytest-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-pytest-patterns
Source: https://github.com/0xDarkMatter/claude-mods/tree/main/skills/python-pytest-patterns
Command: npx skills add https://github.com/0xDarkMatter/claude-mods --skill python-pytest-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes assets (resource) and references (resource) and scripts (resource) components.

What problem does it solve?

This Skill codifies advanced Pytest patterns, including fixtures, parametrization, mocks, and test architecture.

Core Features & Use Cases

  • Fixtures, parametrize, and conftest patterns
  • Mocking, patching, and pytest-mock integration
  • Async testing patterns and test discovery guidance

Quick Start

Scaffold a Pytest suite using the templates and reference patterns to accelerate test development.

Frequently Asked Questions about python-pytest-patterns

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

FAQPage Schema
How do I structure pytest fixtures and conftest files for reusable test setup?

Pytest fixtures provide reusable test setup through function-scoped, session-scoped, or module-scoped decorators. Organize fixtures in conftest.py files at project or package levels to share them across tests, enabling dependency injection and reducing duplication while maintaining test isolation.

What's the best way to parameterize tests to cover multiple input scenarios?

Pytest parametrize decorator lets you run a single test function across multiple input sets, reducing code duplication and improving coverage. Define parameters inline with @pytest.mark.parametrize or use indirect parametrization with fixtures for complex scenarios.

How do I mock external dependencies and patch code in pytest?

Pytest-mock integration provides the mocker fixture for patching functions, classes, and modules without manual teardown. Use mocker.patch() to replace dependencies, control return values, and assert calls were made as expected while keeping tests isolated from external systems.

Can I test asynchronous code with pytest?

Pytest supports async testing through pytest-asyncio plugin, allowing you to mark async test functions with @pytest.mark.asyncio and use await within tests. This enables testing of async fixtures, coroutines, and event-driven code while maintaining standard pytest patterns.

How do I integrate test coverage measurement and CI pipelines with pytest?

Pytest integrates with pytest-cov to generate coverage reports during test runs. Export results to JSON or XML formats for CI pipeline consumption, set coverage thresholds to enforce quality gates, and generate reports for unit, integration, and end-to-end test suites.

What Python and pytest versions does this approach require?

These patterns are designed for pytest 7.0+ and Python 3.9+, ensuring compatibility with modern async features, fixture improvements, and parametrization enhancements. Verify your environment meets these minimums before applying advanced patterns.