test-generator

Generate pytest test cases for Python functions and classes

⭐148stars🔀15forks📁View on GitHub🕐Updated Dec 29, 2025

When & Why to Use This Skill

This Claude skill automates the generation of robust pytest suites for Python applications. It streamlines the development workflow by creating structured test cases that cover happy paths, boundary conditions, and error handling, ensuring high code coverage and reliability while adhering to Pythonic testing best practices such as parametrization and mocking.

Use Cases

  • 1. Automated Unit Testing: Quickly generate comprehensive unit tests for new Python functions and classes to validate core logic and return types.
  • 2. Edge Case Identification: Automatically create test scenarios for boundary values, empty inputs, and invalid data types to improve software resilience.
  • 3. Regression Testing: Build a reliable safety net for legacy codebases to ensure that refactoring or new features do not break existing functionality.
  • 4. Asynchronous Code Validation: Generate specialized test structures for async/await functions using pytest-asyncio patterns.
  • 5. Test Suite Standardization: Enforce consistent testing patterns across a team by utilizing standardized templates for fixtures, assertions, and class-based test organization.
nametest-generator
descriptionGenerate pytest test cases for Python functions and classes
version1.0.0
authorpydantic-deep

Test Generator Skill

You are a test generation expert. When generating tests, follow these guidelines:

Test Structure

Use pytest with the following structure:

import pytest
from module import function_to_test

class TestFunctionName:
    """Tests for function_name."""

    def test_basic_case(self):
        """Test the basic/happy path."""
        result = function_to_test(valid_input)
        assert result == expected_output

    def test_edge_case(self):
        """Test edge cases."""
        ...

    def test_error_handling(self):
        """Test error conditions."""
        with pytest.raises(ExpectedError):
            function_to_test(invalid_input)

Test Categories

1. Happy Path Tests

  • Test normal, expected inputs
  • Verify correct output

2. Edge Cases

  • Empty inputs (empty string, empty list, None)
  • Boundary values (0, -1, max int)
  • Single element collections

3. Error Cases

  • Invalid types
  • Out of range values
  • Missing required parameters

4. Integration Tests (if applicable)

  • Test interactions between components
  • Test with real dependencies where possible

Best Practices

  1. One assertion per test when possible
  2. Descriptive test names that explain what's being tested
  3. Use fixtures for common setup
  4. Use parametrize for testing multiple inputs
  5. Mock external dependencies

Example: Parametrized Test

@pytest.mark.parametrize("input,expected", [
    (0, 0),
    (1, 1),
    (5, 120),
    (10, 3628800),
])
def test_factorial(input, expected):
    assert factorial(input) == expected

Example: Testing Async Functions

import pytest

@pytest.mark.asyncio
async def test_async_function():
    result = await async_function()
    assert result == expected