Skip to main content

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:

  1. The git diff (what changed)
  2. The full file content (context)
  3. 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

Metadata

Release files for difftests 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for difftests 0.1.0
File Size Uploaded
difftests-0.1.0.tar.gz 16.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for difftests 0.1.0
File Interpreter ABI Platform
difftests-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.3 kB

Release files / difftests-0.1.0.tar.gz

Download URL difftests-0.1.0.tar.gz
Size 16.9 kB
Tags Source
SHA-256 checksum
How to use checksums
204c8d75c56cec4ee24fe4627414b93639fb58eccf1768cf792951f08e2e002c
BLAKE2b-256 checksum
How to use checksums
323ec5a404da280fa78f82fdb4b6e3f97e8ec76dd9ee27c7b7f6f9ffd53cbae0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Release files / difftests-0.1.0-py3-none-any.whl

Download URL difftests-0.1.0-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b293e1a6bd64ae8dcb49cb623801fa9f7bd00c818a65fe7a550f4807ade7c70
BLAKE2b-256 checksum
How to use checksums
13de3f857393375c47038bb9f05d9bbfe92ccc85c8046bdef742069689ff31ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page