python-testing

Enforce pytest-based tests with fixtures, mocking, and coverage validation.

1.8k|303|Updated Jan 27, 2026
One-click install
npx skills add https://github.com/xu-xiang/everything-claude-code-zh --skill python-testing-xu-xiang
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-testing
Source: https://github.com/xu-xiang/everything-claude-code-zh/tree/main/skills/python-testing
Command: npx skills add https://github.com/xu-xiang/everything-claude-code-zh --skill python-testing-xu-xiang

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides a disciplined approach to testing Python applications using pytest, TDD workflows, fixtures, mocking, parameterization, and rigorous code coverage; it helps teams reduce regressions and improve test reliability.

Core Features & Use Cases

  • TDD-driven workflow: follows red-green-refactor cycles to drive code quality.
  • Fixtures & parameterization: promotes reusable setup and data-driven tests for robust coverage.
  • Mocking & isolation: isolates units by mocking dependencies to ensure deterministic tests.
  • Code coverage goal: encourages 80%+ coverage with actionable reports and checkpoints.
  • Use Case: For a new Python module, write tests first, run pytest to guide implementation, and progressively increase coverage with fixtures and mocks.

Quick Start

  • Install the tooling: pip install pytest pytest-cov
  • Create tests under a tests/ directory using pytest style.
  • Run tests with coverage: pytest --cov=mypackage --cov-report=term-missing --cov-report=html

Frequently Asked Questions about python-testing

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

FAQPage Schema
How do I start test-driven development with pytest in Python?

To start test-driven development with pytest, follow a red-green-refactor cycle: write failing tests first, implement code to pass them, then refactor. Organize tests in a tests/ directory and run pytest to guide implementation.

How does pytest fixture parameterization work for data-driven testing?

Pytest fixture parameterization works by injecting multiple data sets into a single test function, promoting reusable setup and data-driven tests. This expands robust coverage across various inputs without duplicating test code.

What is the best way to isolate units using mocking in pytest?

The best way to isolate units using mocking in pytest is to mock external dependencies, ensuring deterministic tests. This prevents unpredictable behavior from external services and isolates the specific code block under validation.

How do I enforce code coverage goals using pytest-cov?

To enforce code coverage goals using pytest-cov, run tests with pytest --cov=mypackage --cov-report=term-missing. This generates actionable reports and checkpoints to encourage achieving 80% or higher coverage.

Can I use pytest for testing existing Python modules without rewriting them?

Yes, you can use pytest for testing existing Python modules without rewriting them. It supports conventional testing practices, allowing you to incrementally add tests, fixtures, and mocks to improve reliability and reduce regressions.

Why does pytest test behavior become unreliable without proper isolation?

Pytest test behavior becomes unreliable without proper isolation because external dependencies cause non-deterministic results. Mocking dependencies ensures deterministic tests by controlling the inputs and outputs outside the tested unit.