Run only tests impacted by your code changes (delta-based selection) for pytest.
Project description
pytest-delta
A pytest plugin that filters tests to only those affected by changes since the last successful run.
Installation
pip install pytest-delta
Usage
# Enable delta filtering
pytest --delta
# With debug output
pytest --delta --delta-debug
# With pytest-xdist for parallel execution
pytest --delta -n auto
CLI Options
| Flag | Description |
|---|---|
--delta |
Enable delta filtering |
--delta-file PATH |
Custom delta file path (default: .delta.msgpack in project root) |
--delta-debug |
Show debug info: changed files, affected files, graph stats |
--delta-pass-if-no-tests |
Exit 0 when no tests need to run |
--delta-no-save |
Don't update delta file after run (read-only mode for CI/CD) |
--delta-ignore PATTERN |
Ignore file pattern (repeatable) |
--delta-rebuild |
Force rebuild dependency graph |
Markers
import pytest
@pytest.mark.delta_always
def test_critical():
"""This test runs on every invocation regardless of changes."""
...
How It Works
- On first run, builds a dependency graph by analyzing Python imports
- Saves a
.delta.msgpackfile with the current commit SHA and graph - On subsequent runs, compares current state to last successful run
- Only runs tests that depend on changed files (transitively)
CI Integration
# .github/workflows/test.yml
jobs:
test:
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Need full history for git diff
- name: Run affected tests
run: pytest --delta --delta-pass-if-no-tests -n auto
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
pytest_delta-1.0.0.tar.gz
(12.1 kB
view details)
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 pytest_delta-1.0.0.tar.gz.
File metadata
- Download URL: pytest_delta-1.0.0.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.0 CPython/3.9.18 Darwin/25.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42824f8ec5824c0618865f1ceeeb1d632e3997784b8f2b35218eac8cfb9a5297
|
|
| MD5 |
b14e0d56ae04b33f89803aa0712799e2
|
|
| BLAKE2b-256 |
ee7fd6cd81a0add3ca3d421ea86e1480725a773241039d41b362062b1f38fd92
|
File details
Details for the file pytest_delta-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pytest_delta-1.0.0-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.0 CPython/3.9.18 Darwin/25.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b26ae862ee5181e48c946d1d433d2d3848c70bd2c7534cb2412541e1cf8e39e
|
|
| MD5 |
9985d097462345264316d2647f02c102
|
|
| BLAKE2b-256 |
92a3f811610efdce51856574feb9535cf3e3d79a5ffc43a94ec2fbbfe16d3cf6
|