Agent Skills: TDD Workflow

Guides test-driven development for Python using a five-phase red-green-refactor cycle. Use when asked to write tests first, apply TDD, do test-first implementation, or follow red-green-refactor — designs typed interfaces and Protocol classes, writes failing pytest tests (RED), implements minimal passing code (GREEN), verifies with prek or ruff plus pytest-cov, and enforces a quality gate requiring all tests pass with no lint or type errors and coverage at or above 80 percent.

UncategorizedID: Jamie-BitFlight/claude_skills/python3-tdd

Install this agent skill to your local

pnpm dlx add-skill https://github.com/Jamie-BitFlight/claude_skills/tree/HEAD/plugins/python-engineering/skills/python3-tdd

Skill Files

Browse the full folder contents for python3-tdd.

Download Skill

Loading file tree…

plugins/python-engineering/skills/python3-tdd/SKILL.md

Skill Metadata

Name
python3-tdd
Description
Use when a Python task explicitly requires test-driven development, tests-first implementation, or a red-green-refactor workflow.

TDD Workflow

Consult standards-for-python-development for the shared rules. Load python3-testing for detailed test patterns.

Input

Task: $ARGUMENTS

Phases

1. Design Interface

  • Define only the interface needed to express the behavior under test
  • Preserve the project's existing architecture and typing conventions
  • Load python3-typing when boundary types or models are involved

2. Write Failing Tests

  • Load python3-testing for fixture patterns and test structure
  • Tests must fail initially (RED)
  • AAA pattern; behavioral naming
  • Run the smallest relevant pytest target and confirm RED
  • Record the expected failure reason before running it; RED is valid only when the observed failure demonstrates the missing behavior. A syntax/import/fixture failure or a test that already passes does not establish the requirement.

3. Implement to Pass

  • Minimal code to make tests pass (GREEN)
  • Run the smallest relevant pytest target after each change and compare the observed result with the expected GREEN result
  • Refactor only while tests stay green

4. Verify

# Linting, formatting, and type checking
uv run prek run --files src/ tests/
# Fallback when no .pre-commit-config.yaml:
# uv run ruff check src/ tests/
# uv run ruff format --check src/ tests/

# Tests with coverage
uv run pytest --cov=src --cov-report=term-missing

5. Quality Gate

  • [ ] All tests pass
  • [ ] No lint errors
  • [ ] No type errors
  • [ ] Changed behavior, boundaries, and regressions have appropriate tests
  • [ ] Existing project coverage gate is respected, if configured
  • [ ] Shebang validated on scripts