python-tdd
Drive a change through tight RED → GREEN → REFACTOR cycles using pytest. One failing test, then minimal code to pass, then refactor. Use when coding in python and the user asks for "TDD" ("Test Driven Development"), says "test-first", or wants new behavior added behavior-by-behavior rather than upfront.
- License 许可
- MIT
- 最近更新
- 2026-10-30
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- python-tdd
- description
- Drive a change through tight RED → GREEN → REFACTOR cycles using pytest. One failing test, then minimal code to pass, then refactor. Use when coding in python and the user asks for "TDD" ("Test Driven Development"), says "test-first", or wants new behavior added behavior-by-behavior rather than upfront.
02 资源文件 5
- 参考文档interface-design.md2.3 KB
- 参考文档mocking.md1.3 KB
- 参考文档refactoring.md1.7 KB
- 参考文档troubleshooting.md1.3 KB
- 参考文档writing-tests.md2.9 KB
03 SKILL.md 正文
<what-to-do> Work one behavior at a time. For eachbehavior, execute IN THIS ORDER:
- SCAFFOLD — if the function to test does not exist yet, create a stub for it with its declaration and a
passfor all body. - RED — write ONE failing pytest test that names a behavior through the public interface. Run it. Confirm it fails for the reason you expect (not an import error, not a typo).
- GREEN — write the SMALLEST change that makes it pass. No extra fields, no extra branches, no "while I'm here". Run the test. Confirm it passes.
- REFACTOR — only when green. Clean up duplication, deepen the module, rename for clarity.
- CONTROL — run the full test suit (not only the one you implemented, ALL the tests). Also run linter and type checker. Fix any error before moving to next step.
Then pick the next behavior and repeat.
Before the first cycle, agree with the user on:
- the public interface (function signatures, class API, HTTP endpoint shape — whatever the caller sees)
- the ordered list of behaviors to drive out (3–7 items, prioritised)
- which behaviors are out of scope for this round
Show that list back to the user and get a yes before writing the first test. </what-to-do>
<supporting-info>
The cardinal sin: horizontal slicing
Do not write all the tests first, then all the code. That produces tests of imagined behavior — they assert on the shape you guessed before you knew anything. They pass when the system breaks and break when nothing changed.
Vertical slices only: one test → one implementation → next test. Each cycle teaches you something that informs the next test.
WRONG (horizontal):
RED: test1, test2, test3, test4, test5
GREEN: impl1, impl2, impl3, impl4, impl5
RIGHT (vertical):
RED→GREEN: test1 → impl1
RED→GREEN: test2 → impl2
...
Per-cycle checklist
Before moving to the next behavior:
- [ ] Test names the behavior, not the mechanism
- [ ] Test reaches the code only through the public interface
- [ ] Test would still pass after a plausible internal refactor
- [ ] Production code is the minimum that satisfies the test
- [ ] No speculative fields, branches, or abstractions added
- [ ] Full test file runs green
- [ ] Refactor pass done (or explicitly skipped this cycle)
Further reading
Load on demand, when the cycle calls for it:
- writing-tests.md — what makes a good test: behavior over implementation, GIVEN/WHEN/THEN structure, what not to test, pytest conventions.
- mocking.md — mock at the edges of the system, never inside; prefer fakes over
mock.patch. - interface-design.md — shape production code so tests are easy: dependency injection, return-not-mutate, small surface, SDK-style boundaries.
- refactoring.md — refactor green code (and tests) using named smells: duplication, long function, shallow module, primitive obsession.
- troubleshooting.md — symptoms and fixes when the cycle stalls.
</supporting-info>
04 同仓库更多 Skills
sharpen-language
Grilling session that challenges your plan against the existing domain model, sharpens terminology, and updates documentation (LANGUAGE.md, ADRs) inline as decisions crystallise. Use when user wants to stress-test a plan against their project's language and documented decisions.
security-review
Runs a multi-agent workflow to analyze the security of a project or repository with different lenses. Use when the user wants a thorough multi-angle security review for a feature, refactor, or piece of code, e.g. "review the security of this code base", "perform a security audit of the current application", etc.
review
Simple and generic code review.
release-notes
Generate release notes for a new version. Use when the user asks for a changelog, release notes, or a formatted summary of changes in a repository.
js-tdd
Test-driven development for JavaScript and TypeScript. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.
implement
Simple and generic plan implementation.