fix(test-harness): unique --basetemp per parallel pytest subprocess#1175
Merged
Conversation
Lexus2016
force-pushed
the
fix/pytest-parallel-basetemp-race
branch
from
July 19, 2026 09:11
5952fc2 to
a02b790
Compare
…etemp
run_tests_parallel.py runs one `python -m pytest <file>` subprocess per
file with bounded parallelism. None passed --basetemp, so every subprocess
fell back to the shared default /tmp/pytest-of-<user>/ root. pytest's
numbered-basetemp retention GC ("keep the last few numbered dirs") runs on
session start and rmtree's sibling subprocesses' live basetemp out from
under them, surfacing as flaky
`FileNotFoundError: .../pytest-of-<user>/pytest-N` at fixture setup
(notably the pytest_asyncio tmp_path fixture) with no relation to the code
under test. This is the harness flake that reddened unrelated PRs — e.g.
#1170 slice 4/8 hit ~126 tmp_path setup errors that vanished on rerun.
Allocate a unique --basetemp (tempfile.mkdtemp) per subprocess so the
shared parent, and therefore the cross-process rmtree race, is gone. An
explicit user-supplied --basetemp is respected. The temp tree is reclaimed
on every exit path (normal, timeout, interrupt).
Owner
Author
|
Amended: the initial |
Lexus2016
force-pushed
the
fix/pytest-parallel-basetemp-race
branch
from
July 19, 2026 09:23
a02b790 to
8ff75f5
Compare
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.
Problem
scripts/run_tests_parallel.pyruns onepython -m pytest <file>subprocessper file with bounded parallelism (up to
cpu*2). None passed--basetemp,so every subprocess used the shared default
/tmp/pytest-of-<user>/root.pytest's numbered-basetemp retention GC ("keep the last few
pytest-Ndirs")runs at session start and
rmtrees sibling subprocesses' live basetempout from under them. Result: flaky
FileNotFoundError: /tmp/pytest-of-<user>/pytest-Nat fixture setup(notably the
pytest_asynciotmp_pathfixture), with zero relation to thecode under test.
This is the harness flake that reddens unrelated PRs. Concretely, #1170's
slice 4/8failed with ~126tmp_pathsetup errors intests/gateway/test_telegram_noise_filter.py("all tests passed but pytestexited non-zero") that vanished on rerun.
Fix
Allocate a unique
--basetemp(tempfile.mkdtemp) per subprocess, so theshared parent — and therefore the cross-process
rmtreerace — no longerexists. Details:
--basetempin passthrough args is respected.so local runs don't accumulate one tree per file per invocation. CI runners
are ephemeral anyway.
Testing
Ran the real harness over the tmp_path-heavy files (including the previously
flaky one) in parallel:
ruff checkclean;py_compileclean.hermes-pytest-*temp trees leak after the run (cleanup works).test_durations.jsonis gitignored (harness side-effect, not committed).