write-tests

Write focused pytest tests for Python code with parametrization and mocking.

2|1|Updated Apr 22, 2026
One-click install
npx skills add https://github.com/pytholic/claude-skills --skill write-tests-pytholic
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: write-tests
Source: https://github.com/pytholic/claude-skills/tree/main/write-tests
Command: npx skills add https://github.com/pytholic/claude-skills --skill write-tests-pytholic

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you add focused pytest coverage that protects important behavior without bloating the test suite with redundant or trivial checks.

Core Features & Use Cases

  • Critical path coverage: Tests core business logic, public API contracts, and error handling where regressions matter most.
  • Edge case validation: Covers boundaries, empty inputs, None handling, and failure scenarios that often break production code.
  • Test quality guidance: Encourages readable parametrized tests, AAA structure, fixtures for reuse, and dependency-injection-friendly design.
  • Use case: When a Python module has complex branching logic or a fragile API, this Skill helps generate a minimal test file that verifies the essential behavior and failure modes.

Quick Start

Ask the skill to write focused pytest tests for the target file or code snippet and specify whether you want critical, full, or integration coverage.

Frequently Asked Questions about write-tests

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

FAQPage Schema
How do I write pytest tests that cover edge cases without bloating the test suite?

To write pytest tests that cover edge cases efficiently, use pytest.param-based parametrization to validate boundaries and empty inputs concisely. This approach ensures high-value regression protection for critical logic without redundant checks.

What is the best way to structure pytest tests for critical Python logic?

The best way to structure pytest tests for critical Python logic is using the AAA structure and reusable fixtures for shared setup. This ensures readable tests that verify public API behavior and error handling while maintaining minimal coverage.

How do I use pytest-mock to test error handling in Python functions?

You can use pytest-mock to test error handling in Python functions by mocking external dependencies and integration points. This isolates the target module, allowing you to verify failure scenarios and None handling without requiring the actual dependencies to be present.

When should I use reusable fixtures in pytest?

You should use reusable fixtures in pytest only when shared setup is repeated across multiple tests. This prevents test bloat and keeps the test suite lean while ensuring consistent setup for modules with complex branching logic or fragile APIs.

Does pytest parametrization work for integration testing public API contracts?

Yes, pytest.param-based parametrization works for integration testing public API contracts by allowing you to specify multiple inputs and expected outputs in a single test function. This efficiently validates API behavior and failure modes across various scenarios.