python-testing

athola's avatarfrom athola

Python testing with pytest, fixtures, mocking, and TDD workflows.Triggers: pytest, unit tests, test fixtures, mocking, TDD, test suite, coverage,test-driven development, testing patterns, parameterized testsUse when: writing unit tests, setting up test suites, implementing TDD,configuring pytest, creating fixtures, async testingDO NOT use when: evaluating test quality - use pensive:test-review instead.DO NOT use when: infrastructure test config - use leyline:pytest-config.Consult this skill for Python testing implementation and patterns.

⭐83stars🔀11forks📁View on GitHub🕐Updated Jan 3, 2026

When & Why to Use This Skill

This Claude skill provides a comprehensive framework for Python testing, leveraging the pytest ecosystem to implement robust Test-Driven Development (TDD) workflows. It streamlines the creation of unit and integration tests, manages complex fixtures, and provides advanced mocking patterns to ensure code reliability, high test coverage, and efficient debugging.

Use Cases

  • 1. Test-Driven Development (TDD): Guiding the iterative process of writing failing tests before implementing functional code to ensure software requirements are met from the start.
  • 2. Mocking External Dependencies: Utilizing pytest-mock to isolate units of code by simulating external APIs, databases, or third-party services, ensuring tests are fast and deterministic.
  • 3. Asynchronous Code Testing: Implementing pytest-asyncio patterns to verify the behavior of concurrent operations and async functions in modern Python applications.
  • 4. Test Suite Infrastructure: Configuring pyproject.toml and directory structures for automated test discovery, coverage reporting, and plugin management.
  • 5. CI/CD Pipeline Integration: Preparing and optimizing test suites for automated execution within deployment pipelines to maintain high-quality standards across development teams.
namepython-testing
description|
Triggerspytest, unit tests, test fixtures, mocking, TDD, test suite, coverage,
Use whenwriting unit tests, setting up test suites, implementing TDD,
DO NOT use wheninfrastructure test config - use leyline:pytest-config.
categorytesting
tags[python, testing, pytest, tdd, test-automation, quality-assurance]
tools[test-analyzer, coverage-reporter, test-runner]
complexityintermediate
estimated_tokens900
progressive_loadingtrue

Table of Contents

Python Testing Hub

Testing patterns for pytest, fixtures, mocking, and TDD.

Quick Start

  1. Install pytest and dependencies:

    pip install pytest pytest-cov pytest-asyncio pytest-mock
    
  2. Configure project - Add to pyproject.toml:

    [tool.pytest.ini_options]
    testpaths = ["tests"]
    python_files = ["test_*.py"]
    addopts = "--cov=src --cov-report=html"
    
  3. Create first test - In tests/test_example.py:

    def test_basic():
        assert 1 + 1 == 2
    
  4. Run tests with coverage:

    pytest --cov=src --cov-report=html
    

When to Use

  • Writing unit tests for Python code
  • Setting up test suites and infrastructure
  • Implementing test-driven development (TDD)
  • Creating integration tests for APIs and services
  • Mocking external dependencies and services
  • Testing async code and concurrent operations

Modules

This skill provides focused modules for different testing aspects:

Core Testing

  • unit-testing - Fundamental unit testing patterns with pytest including AAA pattern, basic test structure, and exception testing
  • fixtures-and-mocking - Advanced pytest fixtures, parameterized tests, and mocking patterns for external dependencies
  • async-testing - Testing asynchronous Python code with pytest-asyncio including async fixtures and concurrent operation testing

Infrastructure & Workflow

  • test-infrastructure - Project configuration for pytest including pyproject.toml setup, test directory structure, and coverage configuration
  • testing-workflows - Running tests, CI/CD integration, and automated testing workflows

Quality

  • test-quality - Best practices, anti-patterns to avoid, and quality criteria for Python tests

Progressive Loading

Load modules based on project requirements:

  • Start with unit-testing for fundamental patterns
  • Add fixtures-and-mocking for advanced test setup
  • Include test-infrastructure when setting up new projects
  • Use testing-workflows for CI/CD integration
  • Reference test-quality for best practices
  • Apply async-testing for asynchronous code

Exit Criteria

  • Tests follow AAA pattern
  • Coverage meets project threshold (≥80%)
  • All tests independent and reproducible
  • CI/CD integration configured
  • Clear test naming and organization
  • No anti-patterns present
  • Fixtures used appropriately
  • Mocking only at boundaries

Troubleshooting

Common Issues

If tests aren't found, check that filenames match test_*.py or *_test.py. Use pytest --collect-only to verify discovery. For import errors, ensure the package is installed in editable mode (pip install -e .). If async tests fail, confirm pytest-asyncio is installed and tests use the @pytest.mark.asyncio decorator.