python-testing
Use when implementing new Python code (follow TDD), designing test suites, reviewing test coverage, setting up pytest infrastructure, writing fixtures, mocking dependencies, or performing parametrized testing
Best use case
python-testing is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Use when implementing new Python code (follow TDD), designing test suites, reviewing test coverage, setting up pytest infrastructure, writing fixtures, mocking dependencies, or performing parametrized testing
Teams using python-testing should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/python-testing/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How python-testing Compares
| Feature / Agent | python-testing | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Use when implementing new Python code (follow TDD), designing test suites, reviewing test coverage, setting up pytest infrastructure, writing fixtures, mocking dependencies, or performing parametrized testing
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
SKILL.md Source
# Python Testing Patterns
Comprehensive testing strategies for Python applications using pytest, TDD methodology, and best practices.
## When to Use
- Writing new Python code (follow TDD: red, green, refactor)
- Designing test suites for Python projects
- Reviewing Python test coverage
- Setting up testing infrastructure
- Need guidance on fixtures, mocking, or parametrization
## TDD Cycle
Always follow the Red → Green → Refactor cycle:
1. **RED**: Write a failing test for the desired behavior
2. **GREEN**: Write minimal code to make the test pass
3. **REFACTOR**: Improve code while keeping tests green
## Quick Start
```python
import pytest
# Basic test
def test_addition():
assert 2 + 2 == 4
# Test with fixture
@pytest.fixture
def sample_data():
return {"name": "Alice", "age": 30}
def test_sample_data(sample_data):
assert sample_data["name"] == "Alice"
# Parametrized test
@pytest.mark.parametrize("input,expected", [
("hello", "HELLO"),
("world", "WORLD"),
])
def test_uppercase(input, expected):
assert input.upper() == expected
# Exception testing
def test_divide_by_zero():
with pytest.raises(ZeroDivisionError):
_ = 1 / 0
```
## Core Topics
### Fixtures
Setup and teardown for tests, sharing data, and scopes (function, module, session).
**Details:** `references/fixtures.md`
### Parametrization
Running tests with multiple inputs using `@pytest.mark.parametrize`.
**Details:** `references/parametrization.md`
### Mocking and Patching
Using `unittest.mock` to mock external dependencies and API calls.
**Details:** `references/mocking.md`
### Markers and Test Selection
Custom markers (`@pytest.mark.slow`) and selective test execution.
**Details:** `references/markers.md`
### Async Testing
Testing async functions with `pytest-asyncio`.
**Details:** `references/async_testing.md`
### Test Organization
Directory structure, conftest.py, and grouping related tests.
**Details:** `references/test_organization.md`
## Quick Reference
| Pattern | Usage |
|---------|-------|
| `pytest.raises()` | Test expected exceptions |
| `@pytest.fixture()` | Create reusable test fixtures |
| `@pytest.mark.parametrize()` | Run tests with multiple inputs |
| `@pytest.mark.slow` | Mark slow tests |
| `pytest -m "not slow"` | Skip slow tests |
| `@patch()` | Mock functions and classes |
| `tmp_path` fixture | Automatic temp directory |
| `pytest --cov` | Generate coverage report |
## Running Tests
```bash
# Run all tests
pytest
# Run with coverage
pytest --cov=mypackage --cov-report=html
# Run only fast tests
pytest -m "not slow"
# Run with verbose output
pytest -v
# Run until first failure
pytest -x
# Run last failed tests
pytest --lf
```
## Best Practices
**DO:**
- Follow TDD (write tests before code)
- Test one thing per test
- Use descriptive test names
- Use fixtures to eliminate duplication
- Mock external dependencies
- Aim for 80%+ coverage
- Keep tests fast
**DON'T:**
- Test implementation details
- Use complex conditionals in tests
- Share state between tests
- Catch exceptions in tests (use `pytest.raises`)
- Write tests that are too brittle
**Details:** `references/best_practices.md`
## Common Patterns
### API Endpoint Testing
```python
@pytest.fixture
def client():
app = create_app(testing=True)
return app.test_client()
def test_get_user(client):
response = client.get("/api/users/1")
assert response.status_code == 200
```
### Database Testing
```python
@pytest.fixture
def db_session():
session = Session(bind=engine)
session.begin_nested()
yield session
session.rollback()
session.close()
```
**More patterns:** `references/common_patterns.md`Related Skills
QE Contract Testing
Consumer-driven contract testing for APIs including REST, GraphQL, and event-driven systems with schema validation.
qa-api-testing-contracts
API testing and contract validation. Design and execute schema validation, contract tests, negative testing, and change safety for REST, GraphQL, and gRPC APIs. Use when you need API test plans, contract testing, or CI quality gates.
python-workflow
Python project workflow guidelines. Triggers: .py, pyproject.toml, uv, pip, pytest, Python. Covers package management, virtual environments, code style, type safety, testing, configuration, CQRS patterns, and Python-specific development tasks.
python-workflow-development
Develop Python scripts and modules for building AI workflows and integrations. Use when coding data ingestion, transformation, analysis, and automation pipelines in pilot projects requiring Python automation.
python-typing
Migrate Python codebases to strict type checking with pyright. Use when user wants to add types, fix type errors, set up strict mode, or run a typing migration. Provides setup automation, fix patterns, discipline enforcement, and optional iteration loop support.
python-testing-patterns
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-specialist
Deliver production-quality Python solutions with framework-aware patterns and tests.
python-setup-dev-environment
Set up and run a reproducible Python dev environment with uv, ruff, mypy, and VSCode.
Python Security Scan
Comprehensive security vulnerability scanner for Python projects including Flask, Django, and FastAPI applications. Detects OWASP Top 10 vulnerabilities, injection flaws, insecure deserialization, authentication issues, hardcoded secrets, and framework-specific security problems. Audits dependencies for known CVEs and generates actionable security reports.
python-project
Scaffold and harden Python projects using vpngw-aligned defaults (pyproject/setuptools-scm, src layout, Ruff, pytest, Typer, Pydantic) plus best practices for CLI tools, systemd services, APIs/UI apps, IaC/automation, security/networking, and AI/ML workflows.
python-programmer
Python programmer specialising in functional programming, clean code, documentation, and code quality using ruff and uv.
python-pro
Master Python 3.12+ with modern features, async programming,