- Home
- Skills
- Affaan M
- Everything Claude Code
- Python Testing
python-testing_skill
- JavaScript
46.5k
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill affaan-m/everything-claude-code --skill python-testing- SKILL.md18.4 KB
Overview
This skill documents practical Python testing strategies using pytest and Test-Driven Development (TDD). It covers fixtures, parametrization, mocking, async testing, coverage targets, and test organization to help you build reliable, maintainable test suites.
How this skill works
It outlines a TDD workflow (red, green, refactor), standard pytest patterns, fixture scopes and parametrization, and mocking techniques with unittest.mock. It also specifies coverage goals and tools to measure coverage, plus recommendations for organizing unit, integration, and end-to-end tests.
When to use it
- When starting new Python features—apply TDD to drive design and regression safety.
- When designing or refactoring a test suite to improve reliability and coverage.
- When adding CI test pipelines that enforce coverage thresholds and markers.
- When testing code with external dependencies—use fixtures and mocks to isolate units.
- When testing async code or multiple backends (databases, drivers) with parametrized fixtures.
Best practices
- Follow the TDD cycle: write a failing test, implement minimal code, then refactor.
- Aim for 80%+ test coverage and 100% for critical paths; measure with pytest --cov.
- Keep fixtures focused and use scopes (function/module/session) to balance speed and isolation.
- Prefer parametrization over repetitive tests to cover input permutations cleanly.
- Use mocks and autospec to isolate external systems and catch API misuse.
- Mark slow, integration, and unit tests and run selective sets in CI to speed feedback.
Example use cases
- Drive a new feature using TDD: write failing tests for behavior, implement until green, then refactor.
- Test interactions with multiple database backends using a parametrized db fixture.
- Mock external HTTP APIs in unit tests to validate error handling and retry logic.
- Write async endpoint tests with pytest-asyncio and async fixtures for fast feedback.
- Organize tests into tests/unit, tests/integration, and tests/e2e and use markers to select runs.
FAQ
Aim for 80% overall and require 100% for critical business logic or security paths; enforce with pytest --cov and fail CI if thresholds are not met.
When should I use autouse fixtures?
Use autouse for global setup/teardown that must run for every test (config resets, environment stubs). Avoid overusing autouse fixtures since they can hide implicit dependencies.