
Pytest
Author and run professional Python tests with fixtures, parametrization, mocks, and framework-specific patterns for FastAPI, Django, and Flask.
Overview
pytest is an agent skill most often used in Ship (also Build) that teaches fixtures, parametrization, and framework-aware Python test suites.
Install
npx skills add https://github.com/bobmatnyc/claude-mpm-skills --skill pytestWhat is this skill?
- Fixture-based dependency injection and shared test setup
- @pytest.mark.parametrize for data-driven cases without copy-paste
- Async, database, and mocking patterns for real service tests
- FastAPI, Django, and Flask integration guidance in one skill
- Quick start: test_*.py files, pytest -v, plugins such as pytest-cov
Adoption & trust: 908 installs on skills.sh; 53 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You need trustworthy automated tests for Python services but agents churn out inconsistent patterns, weak isolation, or framework-incompatible setup.
Who is it for?
Python APIs and apps where you want TDD, integration tests with mocks, or FastAPI/Django/Flask-specific test layout.
Skip if: Non-Python stacks, one-off manual QA scripts with no repeatable suite, or teams that standardize on a different test runner exclusively.
When should I use this skill?
Writing unit tests, integration tests, API testing, TDD workflow, testing async code, database testing, or mocking dependencies with pytest.
What do I get? / Deliverables
You get pytest-native test modules, fixtures, and parametrized cases runnable with pytest -v, ready to gate CI or local Ship checks.
- pytest test modules with fixtures and markers
- Parametrized cases and mock/isolation patterns
- Runnable pytest -v command instructions
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Automated test design and execution are canonical Ship work—proving the build before release—even when TDD starts earlier in Build. Testing subphase covers unit, integration, and API suites pytest is built for, including coverage and async/database scenarios.
Where it fits
Spin up test_first API tests with fixtures while implementing a new FastAPI route.
Expand an integration suite with parametrized edge cases before tagging a release.
Add a regression test reproducing a production bug before shipping a hotfix.
How it compares
Procedural pytest playbook for agents—not a hosted test runner or CI product by itself.
Common Questions / FAQ
Who is pytest for?
Indie Python builders and small teams shipping FastAPI, Django, Flask, or plain modules who want agents to write idiomatic pytest instead of generic test stubs.
When should I use pytest?
In Ship when adding regression tests before release, in Build when doing TDD on a new endpoint, or whenever the task is unit tests, API tests, async tests, or mocking with pytest.
Is pytest safe to install?
The skill is documentation-style testing guidance; confirm trust via the Security Audits panel on this page and run generated tests locally before merging.
SKILL.md
READMESKILL.md - Pytest
# pytest - Professional Python Testing ## Overview pytest is the industry-standard Python testing framework, offering powerful features like fixtures, parametrization, markers, plugins, and seamless integration with FastAPI, Django, and Flask. It provides a simple, scalable approach to testing from unit tests to complex integration scenarios. **Key Features**: - Fixture system for dependency injection - Parametrization for data-driven tests - Rich assertion introspection (no need for `self.assertEqual`) - Plugin ecosystem (pytest-cov, pytest-asyncio, pytest-mock, pytest-django) - Async/await support - Parallel test execution with pytest-xdist - Test discovery and organization - Detailed failure reporting **Installation**: ```bash # Basic pytest pip install pytest # With common plugins pip install pytest pytest-cov pytest-asyncio pytest-mock # For FastAPI testing pip install pytest httpx pytest-asyncio # For Django testing pip install pytest pytest-django # For async databases pip install pytest-asyncio aiosqlite ``` ## Basic Testing Patterns ### 1. Simple Test Functions ```python # test_math.py def add(a, b): return a + b def test_add(): assert add(2, 3) == 5 assert add(-1, 1) == 0 assert add(0, 0) == 0 def test_add_negative(): assert add(-2, -3) == -5 ``` **Run tests:** ```bash # Discover and run all tests pytest # Verbose output pytest -v # Show print statements pytest -s # Run specific test file pytest test_math.py # Run specific test function pytest test_math.py::test_add ``` ### 2. Test Classes for Organization ```python # test_calculator.py class Calculator: def add(self, a, b): return a + b def multiply(self, a, b): return a * b class TestCalculator: def test_add(self): calc = Calculator() assert calc.add(2, 3) == 5 def test_multiply(self): calc = Calculator() assert calc.multiply(4, 5) == 20 def test_add_negative(self): calc = Calculator() assert calc.add(-1, -1) == -2 ``` ### 3. Assertions and Expected Failures ```python import pytest # Test exception raising def divide(a, b): if b == 0: raise ValueError("Cannot divide by zero") return a / b def test_divide_by_zero(): with pytest.raises(ValueError, match="Cannot divide by zero"): divide(10, 0) def test_divide_success(): assert divide(10, 2) == 5.0 # Test approximate equality def test_float_comparison(): assert 0.1 + 0.2 == pytest.approx(0.3) # Test containment def test_list_contains(): result = [1, 2, 3, 4] assert 3 in result assert len(result) == 4 ``` ## Fixtures - Dependency Injection ### Basic Fixtures ```python # conftest.py import pytest @pytest.fixture def sample_data(): """Provide sample data for tests.""" return {"name": "Alice", "age": 30, "email": "alice@example.com"} @pytest.fixture def empty_list(): """Provide an empty list.""" return [] # test_fixtures.py def test_sample_data(sample_data): assert sample_data["