python-testing

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

1|Updated Oct 11, 2025
One-click install
npx skills add https://github.com/ibytechaos/claude --skill python-testing-ibytechaos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-testing
Source: https://github.com/ibytechaos/claude/tree/main/plugins/everything-claude-code/skills/python-testing
Command: npx skills add https://github.com/ibytechaos/claude --skill python-testing-ibytechaos

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires pytest, pytest-asyncio, pytest-cov.

What problem does it solve? Writing reliable Python tests requires knowing pytest's fixture system, mocking patterns, parametrization, and coverage tooling, which is easy to get wrong without a structured reference. ## Core Features & Use Cases - TDD Workflow Guidance: Enforces the red-green-refactor cycle with concrete examples for writing failing tests first. - pytest Patterns: Covers fixtures with scopes and teardown, parametrization, custom markers, async testing with pytest-asyncio, and exception assertions. - Mocking & Coverage: Demonstrates unittest.mock patching, autospec, side effects, and coverage targets of 80%+ with pytest-cov configuration. - 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. ## Quick Start Write pytest tests for my Python module using TDD, fixtures, and mocking, then show me how to run them with coverage.

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, uses yield to hand the resource to the test, then runs teardown code after the yield. Fixture scopes like function, module, or session control how often setup runs.

How to mock external API calls in pytest tests?

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. 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 tests via the @pytest.mark.asyncio decorator. Async fixtures can also be defined with async def and yield, and async mocks are verified with assert_awaited_once.

How do I run only specific tests with pytest markers?

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

What code coverage should Python tests target?

Target 80%+ overall coverage with 100% on critical paths. Measure it using pytest --cov=mypackage --cov-report=term-missing to see uncovered lines, and generate HTML reports for detailed inspection.