返回 Skill 列表
extension
分类: 开发与工程无需 API Key

grey-haven-tdd-python

具有使用pytest进行Python测试驱动开发的专业知识,遵循严格的红-绿-重构方法论,熟悉FastAPI的测试模式以及Pydantic模型测试。在使用TDD实现Python功能、编写pytest测试、测试FastAPI端点、采用先测试后编码的方式开发时使用;或者当用户提到'Python TDD'、'pytest'、'FastAPI testing'、'red-green-refactor'、'Python unit tests'、'test-driven Python'或'Python test coverage'时适用。

person作者: jakexiaohubgithub

TDD Python Skill

Python Test-Driven Development following strict red-green-refactor cycle with pytest — sharpened by DDD at Red (model the domain first) and DRY at Refactor (deduplicate same-concept repetition only).

Description

Systematic Python implementation using TDD methodology. Tests are written first and drive design; domain vocabulary drives the tests; duplication is removed only when the same concept repeats, not when syntax coincidentally looks alike.

Discipline Layering

  • Before Red — Model the Domain: Name the entity, value object, or aggregate in the business's language. Decide entity vs. value object. Reject primitive obsession — wrap str/int in EmailAddress, Money, NewType, or pydantic.BaseModel when they carry rules. Keep domain logic out of FastAPI routes.
  • Red: Write a failing test. Name it in domain terms (test_rejects_refund_when_amount_exceeds_daily_limit) — never mechanical (test_returns_false).
  • Green: Minimal code to pass. No speculative abstractions.
  • Refactor — DRY with discipline: Deduplicate only when the same domain concept appears ≥3 times with the same meaning. Three similar lines beats a premature abstraction. Promote recurring primitives to value objects. When uncertain, inline.

What's Included

  • Examples: Python TDD cycles, FastAPI TDD, Pydantic model TDD, value-object modeling
  • Reference: pytest patterns, Python testing best practices, branded-type idioms (NewType, frozen=True)
  • Templates: pytest templates, TDD workflows

Use When

  • Implementing Python features with TDD
  • Modeling domain concepts (entities, value objects, aggregates)
  • FastAPI endpoint development (keeping domain rules out of routes)
  • Pydantic model development
  • Refactoring duplication after a green test

Related Agents

  • tdd-python-implementer

Skill Version: 1.1