Skip to main content
skill CX Codex

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.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add spencerpauly/awesome-cursor-skills --skill python-tdd-with-uv -a claude-code
Open on GitHub

What 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-code

2Manually: put the files in place

~/.claude/skills/python-tdd-with-uv/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/python-tdd-with-uv/

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

Similar skills

Everything for Testing and QA →

From the same set59

setting-up-ci A skill that writes a GitHub Actions pipeline with linting, tests, type-checking and a deploy step. Useful when the repo has no CI yet. CX Codex +1 415installs adding-api-docs This skill writes OpenAPI/Swagger documentation for an API: endpoint schemas, request and response types, and an interactive docs page. CX Codex +1 413installs parallel-test-fixing The skill runs your test suite and assigns each failing test file to a separate subagent for parallel fixes. It helps when multiple test files break simultaneously across a codebase. CX Codex +1 412installs profiling-performance This skill profiles web application CPU performance using browser MCP tools. It captures call stacks and pinpoints slow functions causing interface lag. CX Codex +1 410installs recording-browser-flow-as-test Walks through browser interactions step by step via MCP and outputs a clean Playwright test based on accessibility tree selectors. CX Codex +1 406installs verifying-markdown-formatting Walks a Markdown file through a formatting checklist and fixes what it finds: headings, lists, links, code blocks, spacing. Useful before committing a README or docs. CX Codex +1 404installs exporting-to-png Teaches the agent to render code snippets, Mermaid diagrams, terminal logs, and SVG files into PNG images via CLI utilities or headless browsers. CX Codex +1 401installs parallel-ci-triage Splits failed GitHub Actions jobs across parallel subagents, each fixing its own slice. Useful when CI breaks in several places at once. CX Codex +1 403installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor