What problem does it solve?
Provides clear, repeatable testing practices to prevent regressions, reduce brittle tests, and ensure maintainable Python code through well-structured test suites and coverage goals.
Core Features & Use Cases
- TDD Workflow: Guidance for red-green-refactor cycles to drive design and ensure tests-first development.
- pytest Fundamentals: Test structure, assertions, markers, selection, and configuration via pytest.ini or pyproject.toml.
- Fixtures & Scopes: Reusable setup/teardown patterns, parameterized fixtures, autouse fixtures, and conftest.py sharing.
- Mocking & Async: Patterns for unittest.mock, autospec, mocking context managers, testing async code with pytest-asyncio, and mocking async calls.
- Parametrization & Selection: Parametrize tests and fixtures, use custom markers, and run targeted test subsets for fast feedback.
- Coverage & CI: Practical instructions to measure coverage (target 80%+), enforce critical-path coverage, and integrate tests into CI pipelines.
- Use Case: Implement a test suite for a FastAPI service covering unit, integration, and async endpoints while enforcing coverage gates in CI.
Quick Start
Run pytest with coverage enabled and follow the red-green-refactor cycle to validate new code and meet the 80% coverage target.