python-testing

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

5|15|Updated Jul 8, 2026
One-click install
npx skills add https://github.com/clfigueiredo/hermes-infra-skills --skill python-testing-clfigueiredo
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: python-testing
Source: https://github.com/clfigueiredo/hermes-infra-skills/tree/main/.hermes/skills/curso-hermes/python-testing
Command: npx skills add https://github.com/clfigueiredo/hermes-infra-skills --skill python-testing-clfigueiredo

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Writing reliable Python tests is often inconsistent: developers skip TDD, forget edge cases, or write brittle tests that break on refactors. This Skill provides structured pytest patterns covering the full testing workflow so tests are thorough, maintainable, and fast. ## Core Features & Use Cases - TDD Workflow Guidance: Enforces the red-green-refactor cycle with concrete examples for writing failing tests first, then minimal implementations. - Fixtures, Mocking & Parametrization: Covers fixture scopes, conftest.py sharing, unittest.mock patching, autospec, and parametrized tests for broad input coverage. - Coverage & Test Organization: Targets 80%+ coverage with pytest-cov, marker-based test selection (slow/integration/unit), and a standard tests/ directory layout. - 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. ## Quick Start Write pytest tests for my Python module using TDD, fixtures, mocking, and parametrization 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 tests using TDD?▼

Follow the red-green-refactor cycle: write a failing test for the desired behavior first, implement the minimal code to make it pass, then refactor while keeping tests green. Each test should verify a single behavior with a descriptive name.

How to mock external API calls in pytest?▼

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

Does pytest support async test functions?▼

Yes, with pytest-asyncio you mark tests with @pytest.mark.asyncio and use async def. Async fixtures can yield resources like async HTTP clients, and async mocks are verified with assert_awaited_once.

How do I run only fast tests and skip slow ones in pytest?▼

Mark slow tests with @pytest.mark.slow, register the marker in pytest.ini or pyproject.toml, then run pytest -m "not slow". You can combine markers, such as pytest -m "unit and not slow".

What code coverage should Python tests target?▼

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

Why should tests avoid sharing state between each other?▼

Shared state makes tests order-dependent and produces flaky, hard-to-debug failures. Use function-scoped fixtures so each test gets fresh setup, and rely on teardown or tmp_path for automatic cleanup.