pytest-patterns

Provides structured pytest patterns and best practices for Python test suites.

39|6|Updated Feb 9, 2026
One-click install
npx skills add https://github.com/vladkesler/initrunner --skill pytest-patterns-vladkesler
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytest-patterns
Source: https://github.com/vladkesler/initrunner/tree/main/examples/roles/unit-tester/skills/pytest-patterns
Command: npx skills add https://github.com/vladkesler/initrunner --skill pytest-patterns-vladkesler

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Pytest patterns and best practices for Python test suites.

Core Features & Use Cases

  • Fixtures: centralized setup with conftest.py
  • Parametrize: run multiple input scenarios with @pytest.mark.parametrize
  • Markers and assertions: use @pytest.mark.slow, pytest.raises, and pytest.approx for robust tests.

Quick Start

Execute your tests with pytest and apply these patterns to improve reliability.

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 in conftest.py for reusable test setup?

Pytest fixtures in conftest.py provide centralized test setup by defining reusable functions across your test suite. This pattern isolates initialization logic, ensuring consistent test preconditions and reducing code duplication.

What is the best way to run multiple input scenarios in pytest?

The best way to run multiple input scenarios in pytest is using the @pytest.mark.parametrize decorator. It executes a single test function against defined argument sets, generating distinct test cases for each input combination automatically.

How do I select specific tests in pytest using markers?

You select specific tests in pytest by applying custom markers like @pytest.mark.slow to test functions. This allows targeted execution via command-line selection, isolating slow tests or grouping tests by feature without modifying test logic.

How do I assert exceptions and floating point values in pytest?

To assert exceptions and floating point values in pytest, use pytest.raises to verify expected errors and pytest.approx for numerical comparisons. These assertions ensure your tests fail gracefully on unexpected exceptions and handle float precision accurately.

Do I need to organize my pytest test files in a specific way?

Organizing pytest test files follows standard conventions where test files start with test_ and reside in dedicated directories. Applying these structural patterns alongside fixtures and markers improves test discoverability and suite maintainability.