python-testing

Implements pytest test suites using TDD, fixtures, parametrization, mocking, and coverage reporting.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing reliable Python tests requires consistent patterns for fixtures, mocking, parametrization, and coverage, and this Skill provides a complete pytest playbook so tests are structured correctly from the start. ## Core Features & Use Cases - TDD Workflow Guidance: Enforces the red-green-refactor cycle with concrete examples for writing failing tests first. - Fixtures and Parametrization: Covers fixture scopes, setup/teardown, conftest.py sharing, and parametrized tests to eliminate duplication. - Mocking and Async Testing: Demonstrates unittest.mock patching, autospec, async tests with pytest-asyncio, and exception testing. - Use Case: When building a new FastAPI endpoint, use this Skill to generate a test suite with a client fixture, parametrized input cases, mocked database calls, and a coverage report targeting 80%+. ## Quick Start Write pytest tests for my Python module using TDD with fixtures, parametrization, and coverage reporting.

Frequently Asked Questions about python-testing

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

FAQPage Schema
How do I write pytest fixtures with setup and teardown?▼

Define a function decorated with @pytest.fixture that performs setup, then uses yield to hand the resource to the test, with teardown code after the yield. Fixture scope can be set to function, module, or session to control how often it runs.

How to run the same pytest test with multiple inputs?▼

Use @pytest.mark.parametrize with a list of input and expected value tuples above the test function. The test runs once per parameter set, and you can add ids for readable test names in output.

Does pytest support testing async functions?▼

Yes, pytest supports async tests through the pytest-asyncio plugin. Mark tests with @pytest.mark.asyncio and use async fixtures to test coroutines, and use assert_awaited_once when mocking async calls.

How do I mock external API calls in pytest?▼

Use unittest.mock.patch as a decorator targeting the import path of the external call, then set return_value or side_effect on the mock. Autospec helps catch API misuse by validating calls against the real object's signature.

Why should slow tests be marked separately in pytest?▼

Marking slow tests with @pytest.mark.slow lets you skip them during fast feedback loops using pytest -m "not slow". Markers must be registered in pytest.ini or pyproject.toml to avoid warnings with --strict-markers.

What coverage level should Python tests target?▼

This Skill recommends 80%+ overall code coverage with 100% on critical paths, measured via pytest --cov with term-missing and HTML reports. Coverage alone does not guarantee quality, so combine it with behavior-focused assertions.