testing
Best practices for writing Python tests - use when creating or improving test coverage
When & Why to Use This Skill
This Claude skill provides a comprehensive framework for implementing high-quality Python testing using the pytest framework. It streamlines the process of creating, refactoring, and optimizing test suites by enforcing industry best practices such as the Arrange-Act-Assert pattern, ensuring high code reliability and maintainable test coverage.
Use Cases
- Generating new unit tests for Python features with standardized naming conventions and structures.
- Improving existing test coverage by systematically identifying happy paths, edge cases, and error handling scenarios.
- Refactoring legacy test code to improve isolation and maintainability through the use of pytest fixtures.
- Setting up and optimizing test infrastructure to ensure fast execution speeds and efficient developer workflows.
| name | testing |
|---|---|
| description | Best practices for writing Python tests - use when creating or improving test coverage |
| license | MIT |
| framework | pytest |
Testing Skill
[TEST-PLUGIN-SKILL: testing]
When to Use This Skill
Use this skill when:
- Writing new tests
- Improving test coverage
- Refactoring test code
- Setting up test infrastructure
Test Structure
class TestFeatureName:
"""Tests for specific feature."""
def test_specific_behavior(self) -> None:
"""One test, one assertion pattern."""
# Arrange
input_data = create_test_data()
# Act
result = function_under_test(input_data)
# Assert
assert result == expected_value
Best Practices
- Naming:
test_<behavior>_<condition>_<expected> - Isolation: Each test independent, use fixtures
- Coverage: Test happy path, edge cases, errors
- Speed: Keep unit tests fast (<100ms each)