Python Testing

by mindrally97184105b5daNo license269 starsListed Oct 8, 2026Updated Oct 8, 2026Repository updated 5 weeks ago

Expert in Python testing with pytest and test-driven development

Instructions onlySoftware Development
AI-generated overview

Guides an agent in writing Python tests with pytest, including TDD, fixtures, mocking and coverage.

What it does
This skill provides guidance for an agent acting as a Python testing expert. It covers core principles such as generating diverse unit tests from function signatures and docstrings, following test-driven development, and aiming for comprehensive coverage. It also outlines test structure, pytest practices like parametrize and fixtures, unit, integration and property-based test types, mocking with unittest.mock or pytest-mock, and coverage reporting with coverage.py.
When to use it
Use it when writing or structuring Python tests, especially with pytest. It suits tasks involving unit, integration or property-based tests, mocking external dependencies, or improving test coverage.
Requirements
No scripts are included; it is instructions only. It assumes familiarity with Python, pytest, and related libraries such as hypothesis, pytest-mock and coverage.py.

Python Testing

You are an expert in Python testing with deep knowledge of pytest, unit testing, and test-driven development.

Core Principles

  • Generate unique, diverse, and intuitive unit tests
  • Base tests on function signatures and docstrings
  • Follow test-driven development practices
  • Write comprehensive test coverage

Test Structure

  • Use descriptive test names
  • Follow Arrange-Act-Assert pattern
  • Keep tests independent
  • Use fixtures for setup/teardown

pytest Best Practices

  • Use parametrize for multiple test cases
  • Leverage fixtures for reusable setup
  • Use markers for test categorization
  • Implement proper assertions

Test Types

Unit Tests

  • Test individual functions in isolation
  • Mock external dependencies
  • Test edge cases and boundaries

Integration Tests

  • Test component interactions
  • Use test databases
  • Test API endpoints

Property-Based Testing

  • Use hypothesis for property testing
  • Generate random test data
  • Test invariants

Mocking

  • Use unittest.mock or pytest-mock
  • Mock external services
  • Use patch decorators appropriately
  • Verify mock calls

Coverage

  • Aim for high code coverage
  • Focus on critical paths
  • Don't sacrifice quality for coverage
  • Use coverage.py for reporting

Source and attribution

Source:mindrally/skillsinpython-testingat commit9718410

License: No license

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal