pytest-testing-assistant
Write focused pytest tests as standalone functions (one test per function), avoiding test classes.
When & Why to Use This Skill
The Pytest Testing Assistant is a specialized Claude skill designed to streamline Python testing by generating clean, standalone pytest functions. It emphasizes the AAA (Arrange, Act, Assert) pattern and avoids complex test classes to ensure maximum readability and maintainability. By focusing on single-behavior validation and clear naming conventions, it helps developers build robust test suites that are easy to debug and integrate into CI/CD pipelines.
Use Cases
- Automated Unit Testing: Rapidly generate isolated test cases for Python functions to ensure code reliability and functional correctness.
- Test Suite Modernization: Refactor legacy class-based test suites into modern, flat pytest structures for better clarity and easier maintenance.
- Edge Case Validation: Utilize pytest parametrization to efficiently test multiple input/output matrices without repetitive code loops.
- Test-Driven Development (TDD): Quickly scaffold focused test cases before implementation to define expected behaviors and edge cases.
| name | pytest-testing-assistant |
|---|---|
| description | Write focused pytest tests as standalone functions (one test per function), avoiding test classes. |
Pytest Testing Assistant
Quick start
- Write tests as plain functions; do not use test classes. Aim for one focused test per function/behavior.
- Use clear names:
test_<function>_<behavior>; keep AAA (arrange/act/assert) obvious. - Prefer one primary assertion per test; add minimal supporting checks when necessary.
- Use fixtures sparingly to keep tests readable; favor in-test setup when simple.
- Run with
pytestorpytest path/to/test_file.pyto scope runs. - See
references/pytest_rules.mdfor detailed guidelines and examples.
Workflow
Identify behavior
- Target a single function/behavior per test. Name the test after the behavior being validated.
Write the test
- Use a standalone function
def test_<thing>():(no classes). - Keep a clear arrange/act/assert structure; avoid hidden work in fixtures unless it improves clarity.
- Use parametrization for small input/output matrices instead of loops.
- Use a standalone function
Assertions
- Prefer one main assertion; add secondary checks only when they clarify the outcome.
- Include helpful assertion messages or use expressive matchers for readability.
Run and iterate
- Run
pytest(optionally narrow with paths or-kexpressions). - Refine names and setup for readability and isolation.
- Run
Reference
references/pytest_rules.md: structure rules, naming patterns, and usage tips.