python-testing

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

Updated Mar 25, 2026
One-click install
npx skills add https://github.com/Femad-6/my-skills --skill python-testing-femad-6
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-testing
Source: https://github.com/Femad-6/my-skills/tree/main/.github/skills/python-testing
Command: npx skills add https://github.com/Femad-6/my-skills --skill python-testing-femad-6

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing reliable Python tests requires knowing pytest patterns for fixtures, mocking, parametrization, async code, and coverage, which developers often implement 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. - pytest Patterns: Covers fixtures with scopes and teardown, parametrization, markers, mocking with unittest.mock, async testing with pytest-asyncio, and exception testing. - Coverage & Configuration: Provides pytest.ini and pyproject.toml configurations targeting 80%+ coverage with HTML and terminal reports. - Use Case: When building a new FastAPI endpoint, use this Skill to generate a test suite with a test client fixture, parametrized input cases, mocked database calls, and a coverage report. ## 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, uses yield to provide the resource to the test, and places teardown code after the yield. Fixture scope can be set to function, module, or session to control how often it runs.

How to mock external API calls in pytest?

Use @patch from unittest.mock 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 async test functions?

Yes, with the pytest-asyncio plugin. Mark tests with @pytest.mark.asyncio and define them with async def. Async fixtures can also yield resources like async test clients for testing async endpoints.

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 pytest -m "unit and not slow".

Why should tests avoid sharing state between each other?

Shared state makes tests order-dependent and causes flaky failures that are hard to debug. Each test should be independent, using fixtures to create fresh resources and teardown logic to clean up afterward.