From 13fe1b9d8425ea6ff72eb5fbc704b41f1b2dfe17 Mon Sep 17 00:00:00 2001 From: Brian Gan Date: Wed, 11 Nov 2026 23:44:27 +0000 Subject: [PATCH] pytest: only keep temp dirs of failed tests By default, pytest keeps the temp dirs of every test for the last 3 sessions. Each e2e test clones & checks out a snapshot of the tree under its `tmp_path`, so these add up, and /tmp is often a tmpfs. Set `tmp_path_retention_policy` to `failed` so a test's `tmp_path` is removed as soon as the test passes, and the session's temp dir is removed when all tests pass. The `tmp_path` of a failed test is still kept for debugging. Pass `-o tmp_path_retention_policy=all` to keep the dirs of passing tests too. Test: vpython3 run_tests Change-Id: I2cf464b063d62f155ffdbfed24a12ea9774086d6 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/656093 Reviewed-by: Mike Frysinger Tested-by: Brian Gan Commit-Queue: Brian Gan --- pyproject.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 2d181238c..ceba41ffd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,3 +54,7 @@ markers = """ skip_cq: Skip tests in the CQ. Should be rarely used! e2e: Hermetic end-to-end tests (tests/e2e/). Deselect with -m 'not e2e'. """ +# Only keep the temp dirs of failed tests. By default, pytest keeps the temp +# dirs of all tests for the last 3 runs, and each e2e test has its own checkout. +# Use `-o tmp_path_retention_policy=all` to inspect the dirs of passing tests. +tmp_path_retention_policy = "failed"