tmpdir: write .origin sidecar to record session ownership - #14936
Open
jawauntb wants to merge 2 commits into
Open
tmpdir: write .origin sidecar to record session ownership#14936jawauntb wants to merge 2 commits into
jawauntb wants to merge 2 commits into
Conversation
Each pytest-of-<user>/pytest-N/ session dir now contains a `.origin` file next to `.lock`, recording rootpath, pytest version, PID, and hostname. External cleanup tooling (workstation janitors, CI cleanup steps, editor temp sweeps) can attribute a session dir to its project by reading a file, instead of walking /proc or lsof. Writing is best-effort: any OSError during the write is swallowed so a read-only mount, permissions error, or full disk never breaks a test run. Refs pytest-dev#14935.
jawauntb
force-pushed
the
jb/tmpdir-origin-sidecar
branch
from
August 25, 2026 23:07
bd5af13 to
ce60cd9
Compare
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #14935 (part 1 of 3).
What
Each
pytest-of-<user>/pytest-N/session directory now contains a.originfile next to
.lock, recording:rootpath: the absolute pytest rootpathversion: the pytest version that created itpid: the PID of the creating processhost: the hostname of the creating machineExample:
Why
Right now nothing in the session directory records which rootdir produced it.
External cleanup tooling (workstation janitors, CI cleanup steps, editor
temp sweeps, ad-hoc
du-and-rmpasses) has to reconstruct ownership atdelete time from live process state (
/procwalks,lsof). Getting thatwrong deletes live scratch; getting it conservative leaves disks full.
cat .origincloses that gap without any change to how pytest itself managesretention.
Scope
This PR only adds the sidecar. It is intentionally additive and does not
change any existing behavior:
TempPathFactory,tmp_path,tmp_path_factory,or
--basetemp._rootpathfield onTempPathFactorygets a default ofNone, soexternal callers constructing the factory directly (as several existing
tests do) are unaffected.
Two follow-ups are drafted in #14935 and will land as separate PRs so each
can be reviewed on its own merits:
ensure_deletable(turnsLOCK_TIMEOUT = 3 daysinto a fallback rather than the primary signal).
tmp_path_layout = "per-rootdir"), whichis where the sidecar starts to earn its keep — retention becomes scoped
per project instead of shared across every rootdir a user has ever run
pytest against.
Safety
Writing the sidecar is best-effort — any
OSErrorduring the write isswallowed. A read-only mount, permissions error, or full disk cannot
break a test run. Covered by
TestOriginSidecar::test_origin_write_failure_does_not_break_run.Tests
New tests in
testing/test_tmpdir.py::TestOriginSidecar:test_origin_written_next_to_basetemp— asserts the file exists with allfour fields correctly populated.
test_origin_written_when_basetemp_given—--basetempalso gets asidecar so external tooling can attribute both cases uniformly.
test_origin_write_failure_does_not_break_run— proves the swallow path.Existing
test_tmpdir.pytests (61 passed, 1 skipped locally) plustest_pytester.pyandtest_config.py(340 passed, 1 skipped, 2 xfailedlocally) confirm no regressions.
Changelog
changelog/14935.improvement.rstadded, keyed to the tracking issue.🤖 Generated with Claude Code
https://claude.ai/code/session_017o9EnCzHyTdYKdcXshMyMZ