python-testing

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

Updated Apr 9, 2026
One-click install
npx skills add https://github.com/5onyy/essential-ai-agent-skills --skill python-testing-5onyy
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: python-testing
Source: https://github.com/5onyy/essential-ai-agent-skills/tree/main/.cursor/skills/python-testing
Command: npx skills add https://github.com/5onyy/essential-ai-agent-skills --skill python-testing-5onyy

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 a test client fixture, mocked database calls, parametrized input validation cases, and a coverage report targeting 80%+. ## Quick Start Write pytest tests for my Python module using TDD, fixtures, and mocking with 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, uses yield to provide the resource to the test, and places 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'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 pytest tests by marker?▼

Register custom markers like slow or integration in pytest.ini, tag tests with @pytest.mark.slow, then filter with pytest -m "not slow" or pytest -m integration. Combine expressions with and, or, and not.

What code coverage should Python tests target?▼

This Skill recommends 80% or higher overall coverage with 100% on critical paths. Measure it using pytest --cov=mypackage --cov-report=term-missing to identify untested lines.