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 <vapier@google.com>
Tested-by: Brian Gan <brgan@google.com>
Commit-Queue: Brian Gan <brgan@google.com>
This commit is contained in:
Brian Gan authored and gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com committed 2026-11-12 08:43:05 -08:00
1 parent b1a1cc603a
commit 13fe1b9d84
1 file changed
+4
+4
View File
@@ -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"