python-testing-patterns

Implements Python test suites using pytest fixtures, mocking, parameterization, and coverage reporting.

Updated Apr 13, 2026
One-click install
npx skills add https://github.com/scoots31/engineering-playbook --skill python-testing-patterns-scoots31
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-testing-patterns
Source: https://github.com/scoots31/engineering-playbook/tree/main/references/python-testing-patterns
Command: npx skills add https://github.com/scoots31/engineering-playbook --skill python-testing-patterns-scoots31

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires pytest, pytest-cov, freezegun, requests, and includes references (resource) components.

What problem does it solve? Writing reliable Python tests requires knowing pytest fixtures, mocking strategies, parameterization, and coverage tooling, which is time-consuming to assemble from scratch. ## Core Features & Use Cases - Pytest Patterns: Provides ready-to-use patterns for basic tests, fixtures with setup/teardown, parameterized tests, and exception testing. - Mocking & Isolation: Demonstrates unittest.mock usage, retry behavior testing, time freezing with freezegun, and test markers for organizing suites. - Use Case: When building a new API client, use this Skill to generate a complete test suite with mocked HTTP calls, parameterized input validation tests, and coverage reporting configured to fail below a threshold. ## 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 data, execute the code under test, then verify results. Run tests with the pytest command.

How to mock API requests in Python tests?

Use unittest.mock's patch to replace requests.get or requests.post with a Mock object whose return_value simulates the HTTP response. Configure json.return_value for the payload and verify calls with assert_called_once_with.

What are pytest fixtures and when should I use them?

Pytest fixtures are functions decorated with @pytest.fixture that provide setup and teardown for tests, such as database connections. Use scope parameters like session or module to control how often expensive resources are created.

Does pytest support parameterized tests with multiple inputs?

Yes, pytest supports parameterized tests via @pytest.mark.parametrize, which runs one test function against many input and expected-output pairs. Use pytest.param with id to label individual cases clearly.

How do I measure test coverage in a Python project?

Install pytest-cov and run pytest with --cov=yourpackage to measure coverage. Add --cov-report=term-missing to see uncovered lines and --cov-fail-under=80 to enforce a minimum coverage threshold in CI.

Why do my tests fail when run together but pass individually?

This indicates shared state between tests, violating test isolation. Use fixtures with proper teardown, avoid module-level mutable state, and ensure each test cleans up resources it creates.