python-testing-patterns

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

Updated Jul 29, 2026
One-click install
npx skills add https://github.com/MaiconGambini/opencode-harness-guide --skill python-testing-patterns-maicongambini
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-testing-patterns
Source: https://github.com/MaiconGambini/opencode-harness-guide/tree/main/skills/python-testing-patterns
Command: npx skills add https://github.com/MaiconGambini/opencode-harness-guide --skill python-testing-patterns-maicongambini

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing reliable Python tests requires knowing pytest fixtures, mocking, async testing, and coverage configuration, which is time-consuming to assemble from scratch. ## Core Features & Use Cases - Pytest Patterns: Provides ready-to-use patterns for fixtures, parameterized tests, exception testing, and monkeypatching. - Mocking & Async Testing: Covers unittest.mock usage, pytest-asyncio tests, and temporary file handling with tmp_path. - CI/CD & Coverage: Includes pytest.ini and pyproject.toml configuration plus GitHub Actions workflows with coverage thresholds. - Use Case: When building a new Python service, use this Skill to scaffold a complete test suite with database fixtures, mocked API clients, and coverage reporting wired into CI. ## Quick Start Write pytest tests for my Python module using fixtures, mocking for external API calls, and coverage reporting.

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 with pytest in Python?

Write test functions prefixed with test_ and use plain assert statements to verify results. Follow the Arrange-Act-Assert pattern: set up test data, execute the code under test, then verify the output matches expectations.

How to mock external API calls in pytest tests?

Use unittest.mock's patch function or Mock objects to replace requests.get or requests.post during tests. Configure return_value and side_effect on the mock to simulate successful responses or HTTP errors without real network calls.

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 or test data. Use scope parameters like session, module, or function to control how often fixtures are created.

Does pytest support testing async Python code?

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 can also be defined for asynchronous setup and teardown.

How do I measure test coverage with pytest?

Install pytest-cov and run pytest with the --cov flag targeting your package, such as pytest --cov=myapp tests/. Add --cov-report=term-missing to see uncovered lines and --cov-fail-under=80 to enforce a minimum 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 catching edge cases you did not anticipate.