python-testing-patterns

Implement pytest test suites with fixtures, mocking, parameterization, and coverage reporting.

Updated Nov 30, 2025
One-click install
npx skills add https://github.com/Amakaflow/amakaflow-dev-workspace --skill python-testing-patterns-amakaflow
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: python-testing-patterns
Source: https://github.com/Amakaflow/amakaflow-dev-workspace/tree/main/.claude/skills/python-testing-patterns
Command: npx skills add https://github.com/Amakaflow/amakaflow-dev-workspace --skill python-testing-patterns-amakaflow

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing reliable Python tests requires knowing many pytest patterns—fixtures, mocking, async testing, parameterization—and developers often produce brittle, duplicated, or incomplete test suites without a structured reference. ## Core Features & Use Cases - Pytest Pattern Library: Ready-to-use templates for fixtures, parameterized tests, exception testing, monkeypatching, and temporary file handling. - Advanced Testing Techniques: Covers async test patterns with pytest-asyncio, property-based testing with hypothesis, retry behavior verification, and time mocking with freezegun. - CI/CD and Coverage Setup: Includes GitHub Actions workflow examples, pytest.ini/pyproject.toml configuration, and coverage reporting with pytest-cov. - Use Case: When building a FastAPI service, use this Skill to scaffold unit tests with mocked external API calls, database tests using in-memory SQLite sessions, and a CI pipeline that enforces coverage thresholds. ## Quick Start Write pytest tests for my Python module using fixtures, mocking for external API calls, and parameterized cases for edge inputs.

Frequently Asked Questions about python-testing-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write unit tests in Python with pytest?▼

Write test functions prefixed with test_ and use plain assert statements to verify behavior. Follow the Arrange-Act-Assert pattern: set up test data, execute the code under test, then verify results. Run tests with the pytest command.

How to mock external API calls in pytest tests?▼

Use unittest.mock's patch function or Mock objects to replace external calls like requests.get during tests. Configure return_value or side_effect on the mock to simulate responses, then assert the mock was called with expected arguments.

What is the difference between pytest fixtures and setup methods?▼

Pytest fixtures are declared with the @pytest.fixture decorator and injected into tests as parameters, supporting scopes like function, module, and session. They provide cleaner dependency injection and teardown via yield compared to xUnit-style setup methods.

Does pytest support testing async functions?▼

Yes, pytest supports async tests through the pytest-asyncio plugin. Mark async test functions with @pytest.mark.asyncio and use await inside them. Async fixtures are also supported for setting up asynchronous resources.

How do I measure test coverage in Python?▼

Install pytest-cov and run pytest with the --cov flag targeting your package, such as pytest --cov=myapp. Add --cov-report=term-missing to see uncovered lines or --cov-fail-under=80 to enforce a minimum coverage threshold.

When should I use property-based testing instead of example-based tests?▼

Use property-based testing with hypothesis when you want to verify invariants across many generated inputs, such as reversing a string twice returning the original. It complements example-based tests by discovering edge cases you did not anticipate.