testing

mandersogit's avatarfrom mandersogit

Best practices for writing Python tests - use when creating or improving test coverage

⭐0stars🔀0forks📁View on GitHub🕐Updated Dec 9, 2025

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.
nametesting
descriptionBest practices for writing Python tests - use when creating or improving test coverage
licenseMIT
frameworkpytest

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

  1. Naming: test_<behavior>_<condition>_<expected>
  2. Isolation: Each test independent, use fixtures
  3. Coverage: Test happy path, edge cases, errors
  4. Speed: Keep unit tests fast (<100ms each)