python-testing

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing reliable Python tests requires knowing pytest's fixture system, mocking patterns, parametrization, and coverage tooling, which developers often apply inconsistently or skip entirely. ## 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, exception simulation, and pytest-asyncio patterns. - Use Case: When building a new FastAPI endpoint, use this Skill to generate a test suite with an in-memory database fixture, mocked external API calls, and coverage reporting 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, yields the resource to the test, then runs teardown code after the yield. Use scope parameters like module or session to control how often the fixture runs.

How to mock external API calls in pytest tests?▼

Use unittest.mock's @patch decorator targeting the import path of the external call, then set return_value or side_effect on the mock. Assert call counts with assert_called_once or assert_awaited_once for async functions.

Does pytest support testing async functions?▼

Yes, pytest-asyncio enables async test support through the @pytest.mark.asyncio decorator. Async fixtures can also be defined with async def and yield to provide resources like async HTTP clients.

How do I run only specific tests with pytest markers?▼

Tag tests with custom markers like @pytest.mark.slow, register them in pytest.ini or pyproject.toml, then filter with pytest -m "not slow" or combine expressions like "unit and not slow".

What code coverage should Python tests target?▼

This Skill recommends 80% overall coverage with 100% on critical paths, measured via pytest --cov with term-missing and HTML reports. Coverage below target indicates untested branches that need additional test cases.