Skip to content

ditto prune

Re-run pytest to delete snapshots not in ditto.lock.

With --check, report what would be pruned without deleting anything. A target outside the project (a remote URI, or a file:// path outside it) is only pruned with --shared; --check lists its orphans apart, as shared. Any extra arguments are passed directly to pytest.

Usage:

ditto prune [OPTIONS] [PYTEST_ARGS]...

Options:

  --check   Dry run: report what would be pruned, without deleting.
  --shared  Also delete from targets other checkouts, branches or projects may
            share (any target but a file:// path inside the project, after
            following symlinks). Only safe when each has its own target path.
  --help    Show this message and exit.

Examples

# Prune all stale snapshots
ditto prune

# List what would be pruned
ditto prune --check

# Also prune a remote target that no other branch or project writes to
ditto prune --shared

Behaviour

  • Runs pytest with --ditto-prune, then compares each target the run used with ditto.lock.
  • Deletes each snapshot the lock doesn't record, under the test modules the suite owns. A snapshot created during the same run is never deleted; run ditto lock to record it. Snapshots this run created but the lock doesn't record, and keys the lock records but the backend lacks, are each reported against the target that holds them.
  • The session report groups each deleted snapshot under the target it was deleted from, so a suite with several backends can tell them apart. A snapshot it couldn't delete is listed as not pruned.
  • Needs a ditto.lock; without one it deletes nothing and fails.
  • Fails the run if it can't finish: a target it can't read (with --check too), or a snapshot it couldn't delete. It still processes the other targets, then says how many snapshots it deleted from each target and which ones it couldn't, with the error.
  • Deletes nothing from a target that other checkouts might share (a remote URI, or a file:// path outside the project, after following symlinks) unless you pass --shared. Without it, the run fails and says how many snapshots it left there. Pass --shared only when no other branch or project writes to the target: their snapshots look like orphans. See Sharing a target.
  • --check previews exactly what ditto prune would delete, grouped by target under would prune. Orphans in a shared target are listed apart, under shared, because prune only deletes them with --shared; with ditto prune --check --shared they're listed under would prune too.

Pruning with -k or -m

A filtered run doesn't delete the snapshots of the tests it deselects: ditto.lock records them, so they aren't orphans. The filter only narrows which targets prune examines, to those at least one selected test uses, and prune warns that it was partial. In each target it examines, it deletes every orphan, including those left by deselected tests.

Note

Prune needs a single process. Under pytest-xdist distribution (-n N, or --dist with --tx) it stops with a usage error before running any tests and deletes nothing; if your addopts sets -n, run ditto prune -n 0. See Running tests in parallel.