python-testing

Generates and diagnoses pytest-based unit, integration, and async tests for Python projects.

Updated Jul 6, 2026
One-click install
npx skills add https://github.com/chenziyang110/launchdeck --skill python-testing-chenziyang110
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: python-testing
Source: https://github.com/chenziyang110/launchdeck/tree/main/.claude/skills/python-testing
Command: npx skills add https://github.com/chenziyang110/launchdeck --skill python-testing-chenziyang110

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing reliable Python tests requires choosing the right strategy for mocking, async code, fixtures, and coverage, and mistakes lead to flaky suites and untested edge cases. This Skill provides a structured workflow for designing, generating, and debugging pytest test suites. ## Core Features & Use Cases - Guided Test Generation: Follows a five-phase protocol covering context analysis, strategy selection, test case design, code generation, and verification. - Strategy Decision Tree: Selects between pure unit tests, boundary mocking with unittest.mock or monkeypatch, integration tests, and async tests with pytest-asyncio. - Flaky Test Guardrails: Enforces determinism with tmp_path, freezegun, factory-boy fixtures, and bans time.sleep synchronization. - Use Case: Ask the agent to add tests for a FastAPI endpoint, and it will analyze I/O boundaries, mock external calls, parametrize edge cases, and output runnable pytest code with coverage commands. ## Quick Start Ask the agent to write pytest unit tests with edge case coverage for a specific Python module in your project.

Frequently Asked Questions about python-testing

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

FAQPage Schema
How do I write unit tests with pytest in Python?▼

Write test functions prefixed with test_ in files named test_*.py under a tests directory, using plain assert statements. Use fixtures in conftest.py for setup and @pytest.mark.parametrize to cover multiple input cases.

How to mock external dependencies in pytest tests?▼

Use unittest.mock, pytest's monkeypatch fixture, or libraries like responses and pytest-httpx to mock at architectural boundaries such as HTTP, database, or filesystem calls. Use the tmp_path fixture instead of mocking filesystem operations.

Does pytest support async test functions?▼

Yes, pytest supports async tests through the pytest-asyncio plugin. Mark tests with @pytest.mark.asyncio and set asyncio_mode = auto in pytest.ini or pyproject.toml to avoid deprecation warnings in pytest 8.0+.

Why are my pytest tests flaky and how do I fix them?▼

Flakiness usually comes from time.sleep synchronization, real time or network dependencies, and shared global state. Fix it with freezegun for time, tmp_path for isolation, yield fixtures for cleanup, and pytest-repeat with --count 10 to reproduce issues.

How do I measure and enforce test coverage with pytest?▼

Install pytest-cov and run pytest --cov=src --cov-report=term-missing to see line-by-line coverage. Set fail_under = 80 in the coverage configuration to enforce a minimum threshold in CI pipelines.

When should I not use mocks in Python tests?▼

Avoid mocking internal collaborators or implementation details, since over-mocking couples tests to code structure and hides integration issues. Mock only at external boundaries and prefer integration tests for core logic verification.