From f14bf539c26d186f75aa6da900660527358533de Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 24 Mar 2026 00:47:47 +0100 Subject: [PATCH] gh-146202: Create tmp_dir in regrtest worker (GH-146347) Create tmp_dir in libregrtest.worker since the directory can be different than the --tempdir directory. (cherry picked from commit bcff99cb3f3b887a08c4f0ace1279ced38dd9e62) Co-authored-by: Victor Stinner --- Lib/test/libregrtest/utils.py | 6 ------ Lib/test/libregrtest/worker.py | 3 +++ .../Tests/2026-03-24-00-15-58.gh-issue-146202.LgH6Bj.rst | 3 +++ 3 files changed, 6 insertions(+), 6 deletions(-) create mode 100644 Misc/NEWS.d/next/Tests/2026-03-24-00-15-58.gh-issue-146202.LgH6Bj.rst diff --git a/Lib/test/libregrtest/utils.py b/Lib/test/libregrtest/utils.py index f12cec944fd3bf..c0e8c090670bc3 100644 --- a/Lib/test/libregrtest/utils.py +++ b/Lib/test/libregrtest/utils.py @@ -466,12 +466,6 @@ def get_temp_dir(tmp_dir: StrPath | None = None) -> StrPath: f"unexpectedly returned {tmp_dir!r} on WASI" ) tmp_dir = os.path.join(tmp_dir, 'build') - - # When get_temp_dir() is called in a worker process, - # get_temp_dir() path is different than in the parent process - # which is not a WASI process. So the parent does not create - # the same "tmp_dir" than the test worker process. - os.makedirs(tmp_dir, exist_ok=True) else: tmp_dir = tempfile.gettempdir() diff --git a/Lib/test/libregrtest/worker.py b/Lib/test/libregrtest/worker.py index e0627c4adc0107..c1c7922ae0c651 100644 --- a/Lib/test/libregrtest/worker.py +++ b/Lib/test/libregrtest/worker.py @@ -112,6 +112,9 @@ def main() -> NoReturn: worker_json = sys.argv[1] tmp_dir = get_temp_dir() + # get_temp_dir() can be different in the worker and the parent process. + # For example, if --tempdir option is used. + os.makedirs(tmp_dir, exist_ok=True) work_dir = get_work_dir(tmp_dir, worker=True) with exit_timeout(): diff --git a/Misc/NEWS.d/next/Tests/2026-03-24-00-15-58.gh-issue-146202.LgH6Bj.rst b/Misc/NEWS.d/next/Tests/2026-03-24-00-15-58.gh-issue-146202.LgH6Bj.rst new file mode 100644 index 00000000000000..ef869fe2617256 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2026-03-24-00-15-58.gh-issue-146202.LgH6Bj.rst @@ -0,0 +1,3 @@ +Fix a race condition in regrtest: make sure that the temporary directory is +created in the worker process. Previously, temp_cwd() could fail on Windows if +the "build" directory was not created. Patch by Victor Stinner.