home / skills / xfstudio / skills / python-testing-patterns
This skill helps you implement robust Python testing strategies with pytest, fixtures, mocks, and TDD across unit, integration, and async tests.
npx playbooks add skill xfstudio/skills --skill python-testing-patternsReview the files below or copy the command above to add this skill to your agents.
---
name: python-testing-patterns
description: Implement comprehensive testing strategies with pytest, fixtures, mocking, and test-driven development. Use when writing Python tests, setting up test suites, or implementing testing best practices.
---
# Python Testing Patterns
Comprehensive guide to implementing robust testing strategies in Python using pytest, fixtures, mocking, parameterization, and test-driven development practices.
## Use this skill when
- Writing unit tests for Python code
- Setting up test suites and test infrastructure
- Implementing test-driven development (TDD)
- Creating integration tests for APIs and services
- Mocking external dependencies and services
- Testing async code and concurrent operations
- Setting up continuous testing in CI/CD
- Implementing property-based testing
- Testing database operations
- Debugging failing tests
## Do not use this skill when
- The task is unrelated to python testing patterns
- You need a different domain or tool outside this scope
## Instructions
- Clarify goals, constraints, and required inputs.
- Apply relevant best practices and validate outcomes.
- Provide actionable steps and verification.
- If detailed examples are required, open `resources/implementation-playbook.md`.
## Resources
- `resources/implementation-playbook.md` for detailed patterns and examples.
This skill implements comprehensive Python testing strategies using pytest, fixtures, mocking, parameterization, and test-driven development. It helps teams design reliable unit, integration, and async tests and to integrate testing patterns into CI/CD pipelines. The focus is practical patterns that reduce flakiness and speed maintenance.
The skill inspects project structure and recommends testing layouts, fixture scopes, and parameterization to maximize coverage and minimize duplication. It provides patterns for mocking external dependencies, testing async code, and writing property-based and database tests. It also guides CI test orchestration and TDD workflows with concrete verification steps.
How do I choose fixture scope?
Use function scope for isolated tests, module scope for shared expensive setup across related tests, and session scope for global resources that are expensive to create.
When should I mock vs run integration tests?
Mock dependencies in unit tests to keep them deterministic; add integration tests to validate real interactions and contracts separately.
How to reduce flaky tests?
Avoid shared mutable state, use explicit waits or deterministic synchronization for async code, isolate external resources, and capture environment-dependent behavior with targeted mocks.