python-testing-patterns

python-testing-patterns is a skill for Claude Code, Codex from jh941213/codex-lattice. It costs 66 tokens per session (5,244 once invoked), scanned A, a copy of python-testing-patterns, MIT.

A guide to testing Python programs with pytest, a tool for writing and running Python tests. It covers test fixtures, simulated dependencies, parameterized tests, integration tests, asynchronous code, and test-driven development, where tests are written before or alongside the code.

In plain words
What is it for?
Use it to write unit, integration, functional, database, API, asynchronous, performance, or continuous-integration tests, and to diagnose failing Python tests.
Why use it?
It helps find regressions and isolate failures while avoiding reliance on real external services or databases during tests. It also provides patterns for organizing different kinds of tests.

Skill for Claude CodeCodex

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

Good fit Use it to write unit, integration, functional, database, API, asynchronous, performance, or continuous-integration tests, and to diagnose failing Python tests.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/jh941213/codex-lattice/python-testing-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 jh941213/codex-lattice --skill python-testing-patterns
Clone the repo
git clone --depth 1 https://github.com/jh941213/codex-lattice

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/jh941213/codex-lattice/python-testing-patterns/github.svg)](https://agentmods.dev/skills/jh941213/codex-lattice/python-testing-patterns)
Your own site
<a href="https://agentmods.dev/skills/jh941213/codex-lattice/python-testing-patterns"><img src="https://agentmods.dev/badge/skills/jh941213/codex-lattice/python-testing-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 python-testing-patterns

Your own site · 80×15
<a href="https://agentmods.dev/skills/jh941213/codex-lattice/python-testing-patterns"><img src="https://agentmods.dev/badge/skills/jh941213/codex-lattice/python-testing-patterns.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 66 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 5,244 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 84% 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.00066 $0.05244
Opus 5.5 $0.00026 $0.02098
Sonnet 5.5 $0.00013 $0.01049
Haiku 4.5 $0.00007 $0.00524

Measured 1mo ago against content hash f0988e9202fc, 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

84% identical to python-testing-patterns — 160 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/python-testing-patterns/SKILL.md · 915 lines

How it starts

The opening of the file, as written. The whole thing — 915 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 · 915 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 · 915 lines · 66 tokens per session scan A f0988e9202fc

Subscribe to this mod's changes

python-testing-patterns is a skill published in the GitHub repository jh941213/codex-lattice (19 stars, last pushed 5mo ago), licensed MIT. It adds 66 tokens to every session and 5,244 once invoked, about $0.0003 per session on Opus 5.5. A static security scan graded it A with 1 finding (makes network calls). It is 84% identical to python-testing-patterns, differing in 160 lines, and is treated as a copy.