python-testing

Designs and implements pytest test suites with fixtures, parametrization, mocking, and coverage.

1|2|Updated Nov 25, 2017
One-click install
npx skills add https://github.com/asarchami/dotfiles --skill python-testing-asarchami
Or copy as Structured Prompt for Agentβ–Ό
Please help me install this Agent Skill.
Skill: python-testing
Source: https://github.com/asarchami/dotfiles/tree/main/dot_config/opencode/skills/python/testing
Command: npx skills add https://github.com/asarchami/dotfiles --skill python-testing-asarchami

SYSTEM DOCUMENTATION & REQUIREMENTS

πŸ’‘ This Skill requires pytest, pytest-mock, coverage.

What problem does it solve? Python projects often ship without adequate test coverage, leading to regressions and fragile code. This Skill provides structured guidance for building pytest test suites with proper fixtures, parametrization, mocking, and coverage enforcement. ## Core Features & Use Cases - Pytest Configuration: Sets up pyproject.toml with testpaths, coverage thresholds, and branch coverage settings. - Test Patterns: Provides templates for parametrized tests, shared fixtures via conftest.py, exception testing, and mocking external dependencies. - CI Integration: Guides coverage enforcement (e.g., --cov-fail-under=85) so tests run reliably in continuous integration pipelines. - Use Case: When adding a new module to a Python library, use this Skill to generate a complete tests/ directory with fixtures, edge-case coverage, and a coverage gate before merging. ## Quick Start Ask the agent to create a pytest test suite with fixtures, parametrized cases, and 85% coverage enforcement for your Python module.

Frequently Asked Questions about python-testing

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

FAQPage Schema
How do I write parametrized tests in pytest?β–Ό

Use the @pytest.mark.parametrize decorator with a list of input and expected value tuples. Pytest runs the test function once per parameter set, reporting each case individually for clear failure diagnosis.

How do I enforce a minimum code coverage threshold with pytest?β–Ό

Add --cov=your_package and --cov-fail-under=85 to the addopts setting under [tool.pytest.ini_options] in pyproject.toml. The test run then fails automatically if coverage drops below the threshold.

How do I mock external API calls in pytest tests?β–Ό

Use the mocker fixture from pytest-mock to patch functions, for example mocker.patch("my_lib.client.fetch", return_value={"data": []}). This keeps tests deterministic and removes dependencies on external services.

What is the difference between pytest fixtures and setup functions?β–Ό

Fixtures declared with @pytest.fixture are injected by name into test functions and can be shared across files via conftest.py. They provide cleaner dependency management and teardown compared to traditional xUnit-style setup methods.

When should I use property-based testing instead of example-based tests?β–Ό

Use property-based testing with Hypothesis when input spaces are large or edge cases are hard to enumerate manually. It generates hundreds of inputs automatically, complementing parametrized example tests for known critical values.