pytest-patterns

pytest-patterns is a skill for Claude Code from PramodDutta/qaskills. It costs 31 tokens per session (3,467 once invoked), scanned C, original, MIT.

A guide to testing Python programs with pytest, a testing framework that discovers and runs tests by convention. It covers reusable setup fixtures, parameterised tests, markers, plugins, mocking, and advanced patterns.

In plain words
What is it for?
Use it to write, review, and debug unit or integration tests with fixtures, conftest files, parametrisation, markers, plugins, and mocks.
Why use it?
It helps keep Python tests consistent and reduces repeated setup code while making it easier to check the same behaviour with many inputs.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the qa-essentials plugin — 10 skills shipped together

Good fit Use it to write, review, and debug unit or integration tests with fixtures, conftest files, parametrisation, markers, plugins, and mocks.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/pramoddutta/qaskills/pytest-patterns
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add PramodDutta/qaskills --skill pytest-patterns
Clone the repo
git clone --depth 1 https://github.com/PramodDutta/qaskills

Made for: Claude Code.

Or install qa-essentials, the plugin that ships this one along with the rest of its 10 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for pytest-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/pramoddutta/qaskills/pytest-patterns/github.svg)](https://agentmods.dev/skills/pramoddutta/qaskills/pytest-patterns)
Your own site
<a href="https://agentmods.dev/skills/pramoddutta/qaskills/pytest-patterns"><img src="https://agentmods.dev/badge/skills/pramoddutta/qaskills/pytest-patterns/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for pytest-patterns

Your own site · 80×15
<a href="https://agentmods.dev/skills/pramoddutta/qaskills/pytest-patterns"><img src="https://agentmods.dev/badge/skills/pramoddutta/qaskills/pytest-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 31 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,467 The whole file, excluding the scripts and references it only reads on demand.
Security scan C 2 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00031 $0.03467
Opus 5.5 $0.00012 $0.01387
Sonnet 5.5 $0.00006 $0.00693
Haiku 4.5 $0.00003 $0.00347

Measured 1mo ago against content hash a90db54d9325, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade C, and why

pytest-patterns scanned grade C with 2 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Harvests environment variableshighData exfiltration

Enumerating or grepping the environment for keys collects credentials unrelated to what the mod says it does.

original_env = os.environ.copy()

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

mock_get = mocker.patch("requests.get")
packs/qa-essentials/skills/pytest-patterns/SKILL.md · 572 lines

How it starts

The opening of the file, as written. The whole thing — 572 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Pytest Patterns Skill

You are an expert Python developer specializing in testing with pytest. When the user asks you to write, review, or debug pytest tests, follow these detailed instructions.

Core Principles

  1. Convention over configuration -- pytest discovers tests automatically by naming conventions.
  2. Fixtures for setup -- Use fixtures instead of setUp/tearDown methods.
  3. Parametrize for coverage -- Use @pytest.mark.parametrize for data-driven tests.
  4. Descriptive test names -- Function names should describe the expected behavior.
  5. Minimal test scope -- Each test verifies one behavior.

Project Structure

project/
  src/
    myapp/
      __init__.py
      services/
        user_service.py
        order_service.py
      models/
        user.py
      utils/
        validators.py
  tests/
    __init__.py
    conftest.py
    unit/
      __init__.py
      test_user_service.py
      test_validators.py
    integration/
      __init__.py
      conftest.py
      test_user_api.py
    fixtures/
      user_fixtures.py
  pyproject.toml
  pytest.ini

Configuration

# pytest.ini
[pytest]
testpaths = tests
python_files = test_*.py
python_classes = Test*
python_functions = test_*
addopts = -v --tb=short --strict-markers
markers =
    slow: marks tests as slow (deselect with '-m "not slow"')
    integration: marks integration tests
    smoke: marks smoke tests
    unit: marks unit tests
# pyproject.toml
[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "-v --tb=short --strict-markers --cov=src --cov-report=term-missing"
markers = [
    "slow: marks tests as slow",
    "integration: marks integration tests",
    "smoke: marks smoke tests",
]

[tool.coverage.run]
source = ["src"]
omit = ["tests/*", "*/__init__.py"]

[tool.coverage.report]
fail_under = 80
show_missing = true

Fixtures

Basic Fixtures

# conftest.py
import pytest
from myapp.services.user_service import UserService
from myapp.models.user import User


@pytest.fixture
def sample_user():
    """Create a sample user for testing."""
    return User(
        id="user-123",
        email="[email protected]",
        name="Test User",
        role="user",
    )


@pytest.fixture
def admin_user():
    """Create an admin user for testing."""
    return User(
        id="admin-123",
        email="[email protected]",
        name="Admin User",
        role="admin",
    )


@pytest.fixture
def user_service(mock_user_repo, mock_email_service):
    """Create UserService with mocked dependencies."""
    return UserService(
        user_repo=mock_user_repo,
        email_service=mock_email_service,
    )

Read the full file on GitHub · 572 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 1mo ago First seen · 572 lines · 31 tokens per session scan C a90db54d9325

Subscribe to this mod's changes

pytest-patterns is a skill published in the GitHub repository PramodDutta/qaskills (238 stars, last pushed 9d ago), licensed MIT. It adds 31 tokens to every session and 3,467 once invoked, about $0.0001 per session on Opus 5.5. A static security scan graded it C with 2 findings (harvests environment variables, makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

temporal-python-testing

Test Temporal workflows with pytest, time-skipping, and mocking strategies. Covers unit testing, integration testing, replay testing, and local development setup. Use when implementing Temporal workflow tests or debugging test failures.

wshobson/agents · 45 tokens

python-testing

Python testing best practices using pytest including fixtures, parametrization, mocking, coverage analysis, async testing, and test organization. Use when writing or improving Python tests.

Fmarzochi/EGC · 35 tokens

pytest-expert

Pytest fixtures, parametrize, mock/monkeypatch, async testing with pytest-asyncio, and coverage reporting.

Blazkojj/skillhub · 29 tokens

adk-verify-snippets

Checks that every Python code block in a Markdown file actually compiles and runs, by extracting each block to a temporary file, executing it in an isolated subprocess, and writing a pass/fail report with per-snippet coverage. Use when the user asks to verify, test, or validate the code samples in a README, a guide…

google/adk-python · 149 tokens

adk-setup

Sets up a local ADK Python development environment in a git clone of the open-source adk-python repository: a uv virtual environment, all dependency extras, pre-commit hooks, and a first unit-test run. Runs only when explicitly requested, never on its own. Use when asked to set up, bootstrap, or repair a development…

google/adk-python · 146 tokens

test-generator

Generate pytest test cases for Python functions and classes.

vstorm-co/pydantic-deepagents · 12 tokens