python-tdd-with-uv — Claude Code skill: TDD in Python on uv
Runs your agent through red-green-refactor in Python and sets the project up on uv. Useful when tests come before the code.
npx skills add spencerpauly/awesome-cursor-skills --skill python-tdd-with-uv -a claude-codeWhat python-tdd-with-uv does
The skill gives the agent a fixed order of work: one failing test first, then the minimum code to pass it, then a refactor that keeps behavior unchanged. More than one failing test at a time is off the table, which keeps each cycle short. Before any code it asks three questions: what interfaces change, which behaviors matter most, and whether the design is testable through injected dependencies instead of global state.
Project setup runs on uv. The skill checks uv --version, runs uv init when there is no pyproject.toml, adds pytest and pytest-cov as dev dependencies, and confirms the runner sees the suite with uv run pytest --co. Every later command goes through uv run, so you never activate a virtualenv by hand. Both pyproject.toml and uv.lock are meant to be committed.
Mocks are allowed only at system boundaries: I/O, network, the clock. Tests should assert observable behavior rather than internal structure. If your project does not use uv, the dependency steps need rewriting for whatever manager you do use — worth checking before you hand this to an agent.
What it helps with
- set up a Python project on uv with pytest and coverage
- write the test before the implementation
- keep the red-green-refactor cycle short
- decide where mocks belong in a test suite
- confirm the test runner actually picks up the suite
Example prompts for the agent
- Set up this Python project on uv and add pytest with coverage
- Write one failing test for this function, then the minimum code to pass it
- Run the tests with uv run pytest -x and show me what fails
How to install python-tdd-with-uv
1Skills CLI (Vercel)
npx skills add spencerpauly/awesome-cursor-skills --skill python-tdd-with-uv -a claude-code2Manually: put the files in place
~/.claude/skills/python-tdd-with-uv/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/python-tdd-with-uv/
1Skills CLI (Vercel)
npx skills add spencerpauly/awesome-cursor-skills --skill python-tdd-with-uv -a codex2Manually: put the files in place
.agents/skills/python-tdd-with-uv/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add spencerpauly/awesome-cursor-skills --skill python-tdd-with-uv -a cursor2Manually: put the files in place
.cursor/skills/python-tdd-with-uv/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install spencerpauly/awesome-cursor-skills python-tdd-with-uv2Manually: put the files in place
.github/skills/python-tdd-with-uv/SKILL.md1Skills CLI (Vercel)
npx skills add spencerpauly/awesome-cursor-skills --skill python-tdd-with-uv -a gemini-cli2Platform CLI
gemini skills install https://github.com/spencerpauly/awesome-cursor-skills --path resources/python-tdd-with-uvManually: put the files in place
.devin/skills/python-tdd-with-uv/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add spencerpauly/awesome-cursor-skills --skill python-tdd-with-uv -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about python-tdd-with-uv
How do I install python-tdd-with-uv in Claude?
Run npx skills add spencerpauly/awesome-cursor-skills --skill python-tdd-with-uv -a claude-code. The skill lands at ~/.claude/skills/python-tdd-with-uv/SKILL.md.
What does python-tdd-with-uv do?
It drives the agent through red-green-refactor in Python: one failing test, minimal implementation, refactor. It also covers standing up a project on uv with pytest and pytest-cov.
Do I need uv if my project already uses something else?
The skill is built around uv: version check, uv init, uv add --dev, and running everything through uv run. With another manager you would rewrite the setup steps.
Source text
SKILL.md · CC0-1.0
---
name: python-tdd-with-uv
description: Test-driven development in Python using uv as the package manager. Covers the red-green-refactor cycle, vertical slicing, and uv project setup.
user-invocable: true
---
# Python TDD with uv
Write Python code test-first using `uv` for fast dependency and environment management.
## Setting Up the Project
1. Check if `uv` is installed: `uv --version`
2. If the project doesn't have a `pyproject.toml`, initialize:
```bash
uv init
```
3. Add pytest as a dev dependency:
```bash
uv add --dev pytest pytest-cov
```
4. Confirm the test runner works:
```bash
uv run pytest --co
```
## TDD Workflow — Vertical Slicing
Work in small cycles. Never write more than one failing test at a time.
### Planning Phase
Before writing code, answer:
1. What interface changes are needed? (functions, classes, APIs)
2. Which behaviors matter most? (prioritize critical paths)
3. Can we design for testability? (inject dependencies, avoid global state)
### The Cycle
```
RED → Write ONE failing test for the next behavior
GREEN → Write the MINIMUM code to make it pass
REFACTOR → Clean up without changing behavior
REPEAT
```
**Rules:**
- Never write implementation before a failing test exists
- Never write more than one failing test at a time
- Run `uv run pytest` after every change
- Tests must assert observable behavior, not implementation details
- Mocks should only be used at system boundaries (I/O, network, clock)
### Test File Structure
```python
# tests/test_<module>.py
class TestFeatureName:
"""Group related behaviors."""
def test_does_expected_thing_when_given_input(self):
result = function_under_test(input_value)
assert result == expected
def test_raises_when_given_invalid_input(self):
with pytest.raises(ValueError):
function_under_test(bad_input)
```
### Running Tests
```bash
uv run pytest # all tests
uv run pytest tests/test_foo.py # single file
uv run pytest -k "test_name" # by name pattern
uv run pytest --cov=src # with coverage
uv run pytest -x # stop on first failure
```
## uv Essentials
```bash
uv add <package> # add dependency
uv add --dev <package> # add dev dependency
uv remove <package> # remove dependency
uv sync # sync environment from lockfile
uv run <command> # run in managed environment
uv lock # regenerate lockfile
```
- Always use `uv run` to execute commands — never activate venvs manually
- Commit both `pyproject.toml` and `uv.lock`
## References
- [mattpocock/skills — TDD skill](https://github.com/mattpocock/skills) — vertical-slice TDD philosophy
- [nizos/tdd-guard](https://github.com/nizos/tdd-guard) — automated TDD enforcement via hooks
- [s2005/uv-skill](https://github.com/s2005/uv-skill) — uv workflow patterns
© spencerpauly · CC0-1.0 · spencerpauly/awesome-cursor-skills