Skip to main content

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

  1. On first run, builds a dependency graph by analyzing Python imports
  2. Saves a .delta.msgpack file with the current commit SHA and graph
  3. On subsequent runs, compares current state to last successful run
  4. 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


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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_delta-1.0.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

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

Hashes for pytest_delta-1.0.0.tar.gz
Algorithm Hash digest
SHA256 42824f8ec5824c0618865f1ceeeb1d632e3997784b8f2b35218eac8cfb9a5297
MD5 b14e0d56ae04b33f89803aa0712799e2
BLAKE2b-256 ee7fd6cd81a0add3ca3d421ea86e1480725a773241039d41b362062b1f38fd92

See more details on using hashes here.

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

Hashes for pytest_delta-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b26ae862ee5181e48c946d1d433d2d3848c70bd2c7534cb2412541e1cf8e39e
MD5 9985d097462345264316d2647f02c102
BLAKE2b-256 92a3f811610efdce51856574feb9535cf3e3d79a5ffc43a94ec2fbbfe16d3cf6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page