AI-powered test generator from git diffs — write tests for what you changed
Project description
difftests
AI test generator from git diffs — write tests for what you just changed.
Stop writing tests from scratch. difftests analyzes your git diff and generates
tests that cover exactly what you changed — including edge cases and error conditions.
Install
pip install difftests
Set your API key (or use Ollama for zero-cost local generation:
export ANTHROPIC_API_KEY=your-key # Claude (default)
export OPENAI_API_KEY=your-key # or OpenAI
# or use --provider ollama # local, no API key needed
Usage
# Generate tests for staged changes (most common)
difftests
# Generate tests for all changes vs main branch
difftests --diff main
# Generate tests for a specific file
difftests --file src/auth.py
# Specify the test framework (auto-detected by default)
difftests --framework pytest # default for Python
difftests --framework jest # for JavaScript
difftests --framework vitest # for TypeScript
difftests --framework rspec # for Ruby
difftests --framework go # for Go
# Save generated tests to a directory
difftests --output tests/
# Generate AND run tests immediately
difftests --run
# Copy to clipboard
difftests --copy
# Add context for better generation
difftests --context "This is a payment module, be thorough with security tests"
# Use local Ollama (free, no API key)
difftests --provider ollama --model qwen2.5:7b
# Raw output for piping
difftests --raw > tests/test_new.py
Frameworks
| Language | Default | Alternatives |
|---|---|---|
| Python | pytest |
unittest |
| JavaScript | jest |
|
| TypeScript | vitest |
jest |
| Ruby | rspec |
|
| Go | go |
What Makes difftests Different
Understands your diff, not just your code. difftests focuses on the exact functions and methods you changed, not random parts of your codebase. The AI is shown:
- The git diff (what changed)
- The full file content (context)
- Instructions to focus on edge cases, error conditions, and security
Works with any LLM. Claude, OpenAI, or local Ollama — bring your own model.
Generates real tests, not boilerplate. The AI is explicitly instructed to:
- Test edge cases (null, empty, boundary values)
- Test error conditions (
pytest.raises, exception handling) - Mock external dependencies (databases, HTTP, file I/O)
- Use the framework's best practices (not generic asserts)
Developer Workflow Integration
difftests works best as part of the AI-powered developer workflow:
# 1. Morning: generate standup from yesterday's commits
standup-ai ~/projects/myapp
# 2. Write code, then review before committing
critiq # AI review of staged changes
difftests --staged # generate tests for what you just wrote
pytest tests/ # run them
# 3. Generate conventional commit message
gpr --commit-run
# 4. Generate PR description
gpr
# 5. Review a teammate's PR (also generate tests for their changes)
difftests --diff main --output tests/
prcat 42
# 6. At release: generate CHANGELOG
changelog-ai --from v0.1.0 --prepend CHANGELOG.md
Providers
| Provider | Command | Notes |
|---|---|---|
| Claude (default) | --provider claude |
Best results; requires ANTHROPIC_API_KEY |
| OpenAI | --provider openai |
Requires OPENAI_API_KEY |
| Ollama | --provider ollama |
Free, runs locally; no API key needed |
Related Tools
- critiq — AI code reviewer (find issues before pushing)
- critiq-action — critiq as a GitHub Action for CI
- gpr — AI commit messages + PR descriptions
- prcat — AI reviewer for teammates' pull requests
- gitbrief — git-history-aware context packer for LLMs
- standup-ai — daily standup from git commits
- changelog-ai — AI-generated CHANGELOG
- chronicle — AI git history narrator
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file difftests-0.1.0.tar.gz.
File metadata
- Download URL: difftests-0.1.0.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
204c8d75c56cec4ee24fe4627414b93639fb58eccf1768cf792951f08e2e002c
|
|
| MD5 |
b5cdbea2a4271a4c913137612aa23a91
|
|
| BLAKE2b-256 |
323ec5a404da280fa78f82fdb4b6e3f97e8ec76dd9ee27c7b7f6f9ffd53cbae0
|
File details
Details for the file difftests-0.1.0-py3-none-any.whl.
File metadata
- Download URL: difftests-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b293e1a6bd64ae8dcb49cb623801fa9f7bd00c818a65fe7a550f4807ade7c70
|
|
| MD5 |
9191e295fa78a2075faaf4fc50fbf14b
|
|
| BLAKE2b-256 |
13de3f857393375c47038bb9f05d9bbfe92ccc85c8046bdef742069689ff31ad
|