pytest

Provide structured pytest fixtures, mocking, and parametrization patterns for Python tests.

3|Updated Apr 5, 2023
One-click install
npx skills add https://github.com/mrp4sten/.dotfiles --skill pytest-mrp4sten
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytest
Source: https://github.com/mrp4sten/.dotfiles/tree/main/development/IA/opencode/skill/pytest
Command: npx skills add https://github.com/mrp4sten/.dotfiles --skill pytest-mrp4sten

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Pytest testing patterns for Python help developers write reliable, readable tests and catch regressions early by showcasing best practices for fixtures, mocking, and test organization.

Core Features & Use Cases

  • Fixtures and parametrization to reduce duplication and increase test coverage.
  • Mocking and monkeypatching patterns to isolate units.
  • Markers and test organization strategies to support CI pipelines and large codebases.
  • Real-world examples showing common pytest workflows and debugging.

Quick Start

Install and apply pytest patterns in your project to begin writing robust tests immediately.

Frequently Asked Questions about pytest

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

FAQPage Schema
How do I use pytest fixtures to reduce duplication in Python unit tests?

Pytest fixtures provide a structured way to manage test setup and teardown, reducing duplication in Python unit tests. By defining reusable setup code in functions or conftest.py files, you can inject dependencies across multiple test cases to increase coverage.

What is the best way to isolate units with mocking and monkeypatching in pytest?

Mocking and monkeypatching in pytest isolate units by replacing external dependencies with controlled test doubles. This pattern allows you to test specific components without triggering side effects from external services or complex internal modules.

How do I parametrize tests in pytest to increase test coverage?

Parametrizing tests in pytest allows you to run the same test function against multiple sets of arguments. By applying the parametrize marker, you can increase test coverage efficiently and reduce duplicate test code across your Python project.

Can I use pytest markers to organize tests for CI pipelines and large codebases?

Yes, pytest markers support test organization strategies for CI pipelines and large codebases. You can apply custom labels to tests, allowing you to selectively run or skip specific test groups during continuous integration workflows.

How does conftest usage work when structuring pytest patterns across Python projects?

Conftest usage centralizes fixture definitions and shared hook logic across Python projects. By placing a conftest.py file in your test directory, pytest automatically discovers and applies these shared patterns to relevant test modules without explicit imports.