What problem does it solve?
Inconsistent, brittle, or missing tests slow development and allow regressions to reach production; this skill provides practical patterns and rules to make Python test suites reliable, maintainable, and fast. It clarifies how to adopt test-driven development, write clear fixtures, mock external dependencies safely, and set coverage targets so teams can merge with confidence.
Core Features & Use Cases
- TDD workflow: guidance for red → green → refactor cycles and how to structure iterations for one-shot implementation.
- pytest fundamentals: recommended test organization, markers, selection strategies, and configuration for CI-friendly runs.
- Fixtures & scopes: patterns for reusable fixtures at function, module, and session scopes with setup/teardown best practices.
- Parametrization & markers: how to run matrix tests, provide readable test ids, and separate slow/integration tests from unit suites.
- Mocking & async testing: safe patterns for patching, autospec, async tests, and asserting calls and exceptions without hitting external services.
- Coverage and CI: target coverage guidance (80%+ and 100% for critical paths), integration with pytest --cov, and enforcing coverage gates in pipelines.
- Use case: convert a brittle integration suite into a fast, deterministic set of unit and integration tests with parametrized backends and mock isolation for external APIs.
Quick Start
Ask for a failing pytest unit test for a new function add(a, b), implement the minimal function to make it pass, and then propose a safe refactor while preserving all tests.