affaan-m avatar

Python Testing

This covers the essentials of pytest-based testing with a strong TDD bent. You get fixtures with different scopes, parametrization patterns, mocking with unittest.mock, and the red-green-refactor cycle baked into the workflow. It pushes for 80% coverage as standard and 100% on critical paths, which is reasonable. The examples are practical: database setup/teardown, API auth headers in conftest.py, running tests by markers to skip slow integration tests. If you're building Python projects and want a reference that doesn't just show syntax but actually demonstrates when to use module-scoped fixtures versus function-scoped ones, this gets you there without the usual tutorial bloat.

skills.sh installs
6K
GitHub stars
300.3K
last updated
Aug 21, 2026

Install

$ npx -y skills add affaan-m/ecc --skill python-testing --agent claude-code

Installs into .claude/skills of the current project.

Files

Python Testing Patterns

Comprehensive testing strategies for Python applications using pytest, TDD methodology, and best practices.

When to Activate

  • Writing new Python code (follow TDD: red, green, refactor)
  • Designing test suites for Python projects
  • Reviewing Python test coverage
  • Setting up testing infrastructure

Core Testing Philosophy

Test-Driven Development (TDD)

Always follow the TDD cycle:

  1. RED: Write a failing test for the desired behavior
  2. GREEN: Write minimal code to make the test pass
  3. REFACTOR: Improve code while keeping tests green
# Step 1: Write failing test (RED)
def test_add_numbers():
    result = add(2, 3)
    assert result == 5

# Step 2: Write minimal implementation (GREEN)
def add(a, b):
    return a + b

# Step 3: Refactor if needed (REFACTOR)

Coverage Requirements

  • Target: 80%+ code coverage
  • Critical paths: 100% coverage required
  • Use pytest --cov to measure coverage
pytest --cov=mypackage --cov-report=term-missing --cov-report=html

pytest Fundamentals

Basic Test Structure

import pytest

Sponsors

Details

Repository
github.com/affaan-m/ecc
Categories
Testing & QA, Python
First seen
Jul 14, 2026

More from affaan-m/ecc

All 263
1affaan-m avatarlaravel-tddaffaan-m/eccLaravel testing strategies with PHPUnit, Pest, model factories, HTTP tests, Sanctum authentication testing, mocking, and coverage.6Kskills.sh installs
2affaan-m avatarreact-testingaffaan-m/eccReact component testing with React Testing Library, Vitest/Jest, MSW for network mocking, accessibility assertions with axe, and the decision boundary between c5.8Kskills.sh installs
3forcedotcom avataragentforce-testforcedotcom/sf-skillsWrite, run, and analyze structured test suites for Agentforce agents — functional AND security. TRIGGER when: user writes or modifies test spec YAML (AiEvaluati5.8Kskills.sh installs
4affaan-m avatardjango-tddaffaan-m/eccDjango testing strategies with pytest-django, TDD methodology, factory_boy, mocking, coverage, and testing Django REST Framework APIs.5.8Kskills.sh installs
5affaan-m avatarkotlin-testingaffaan-m/eccKotlin testing patterns with Kotest, MockK, coroutine testing, property-based testing, and Kover coverage. Follows TDD methodology with idiomatic Kotlin practic5.7Kskills.sh installs
6jeffallan avatartest-masterjeffallan/claude-skillsGenerates test files, creates mocking strategies, analyzes code coverage, designs test architectures, and produces test plans and defect reports across function5.7Kskills.sh installs