python-testing-patterns

python-testing-patterns is a skill for Claude Code, Codex from Awish021/opencode. It costs 38 tokens per session (5,211 once invoked), scanned A, a copy of python-testing-patterns, MIT.

A guide to testing Python programs with pytest, reusable test setup, test doubles, and test-driven development (TDD), where tests are written before the code.

In plain words
What is it for?
Writing unit, integration, API, database, asynchronous, and concurrent-code tests; setting up test suites and continuous testing; and debugging failing tests.
Why use it?
It helps you choose suitable tests and organize them so bugs are found earlier and failures are easier to investigate.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Writing unit, integration, API, database, asynchronous, and concurrent-code tests; setting up test suites and continuous testing; and debugging failing tests.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/awish021/opencode/pytest-tests
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 Awish021/opencode --skill pytest-tests
Clone the repo
git clone --depth 1 https://github.com/Awish021/opencode

Made for: Claude Code, Codex.

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 python-testing-patterns

README.md
[![agentmods](https://agentmods.dev/badge/skills/awish021/opencode/pytest-tests/github.svg)](https://agentmods.dev/skills/awish021/opencode/pytest-tests)
Your own site
<a href="https://agentmods.dev/skills/awish021/opencode/pytest-tests"><img src="https://agentmods.dev/badge/skills/awish021/opencode/pytest-tests/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 python-testing-patterns

Your own site · 80×15
<a href="https://agentmods.dev/skills/awish021/opencode/pytest-tests"><img src="https://agentmods.dev/badge/skills/awish021/opencode/pytest-tests.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 38 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 5,211 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. A grade says what 26 rules found in the file — not that it is safe.
Origin 89% copy Near-identical to another mod 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.00038 $0.05211
Opus 5.5 $0.00015 $0.02084
Sonnet 5.5 $0.00008 $0.01042
Haiku 4.5 $0.00004 $0.00521

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

Security

Grade A, and why

python-testing-patterns scanned grade A with 1 finding 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.

Makes network callslowCapability

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

response = requests.get(f"{self.base_url}/users/{user_id}")
Origin

This is a copy

89% identical to python-testing-patterns — 156 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

skills/pytest-tests/SKILL.md · 911 lines

How it starts

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

Python Testing Patterns

Comprehensive guide to implementing robust testing strategies in Python using pytest, fixtures, mocking, parameterization, and test-driven development practices.

When to Use This Skill

  • Writing unit tests for Python code
  • Setting up test suites and test infrastructure
  • Implementing test-driven development (TDD)
  • Creating integration tests for APIs and services
  • Mocking external dependencies and services
  • Testing async code and concurrent operations
  • Setting up continuous testing in CI/CD
  • Implementing property-based testing
  • Testing database operations
  • Debugging failing tests

Core Concepts

1. Test Types

  • Unit Tests: Test individual functions/classes in isolation
  • Integration Tests: Test interaction between components
  • Functional Tests: Test complete features end-to-end
  • Performance Tests: Measure speed and resource usage

2. Test Structure (AAA Pattern)

  • Arrange: Set up test data and preconditions
  • Act: Execute the code under test
  • Assert: Verify the results

3. Test Coverage

  • Measure what code is exercised by tests
  • Identify untested code paths
  • Aim for meaningful coverage, not just high percentages

4. Test Isolation

  • Tests should be independent
  • No shared state between tests
  • Each test should clean up after itself

Quick Start

# test_example.py
def add(a, b):
    return a + b

def test_add():
    """Basic test example."""
    result = add(2, 3)
    assert result == 5

def test_add_negative():
    """Test with negative numbers."""
    assert add(-1, 1) == 0

# Run with: pytest test_example.py

Fundamental Patterns

Pattern 1: Basic pytest Tests

# test_calculator.py
import pytest

class Calculator:
    """Simple calculator for testing."""

    def add(self, a: float, b: float) -> float:
        return a + b

    def subtract(self, a: float, b: float) -> float:
        return a - b

    def multiply(self, a: float, b: float) -> float:
        return a * b

    def divide(self, a: float, b: float) -> float:
        if b == 0:
            raise ValueError("Cannot divide by zero")
        return a / b


def test_addition():
    """Test addition."""
    calc = Calculator()
    assert calc.add(2, 3) == 5
    assert calc.add(-1, 1) == 0
    assert calc.add(0, 0) == 0


def test_subtraction():
    """Test subtraction."""
    calc = Calculator()
    assert calc.subtract(5, 3) == 2
    assert calc.subtract(0, 5) == -5


def test_multiplication():
    """Test multiplication."""
    calc = Calculator()
    assert calc.multiply(3, 4) == 12
    assert calc.multiply(0, 5) == 0


def test_division():
    """Test division."""
    calc = Calculator()
    assert calc.divide(6, 3) == 2
    assert calc.divide(5, 2) == 2.5


def test_division_by_zero():
    """Test division by zero raises error."""
    calc = Calculator()
    with pytest.raises(ValueError, match="Cannot divide by zero"):
        calc.divide(5, 0)

Read the full file on GitHub · 911 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 · 911 lines · 38 tokens per session scan A 0ad885ec9c28

Subscribe to this mod's changes

python-testing-patterns is a skill published in the GitHub repository Awish021/opencode (11 stars, last pushed 4mo ago), licensed MIT. It adds 38 tokens to every session and 5,211 once invoked, about $0.0002 per session on Opus 5.5. A static security scan graded it A with 1 finding (makes network calls). It is 89% identical to python-testing-patterns, differing in 156 lines, and is treated as a copy.