Skip to content

Commit 36934a1

Browse files
authored
gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)
1 parent 6b33000 commit 36934a1

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

Lib/test/libregrtest/runtest_mp.py

+21-15
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ def run_test_in_subprocess(testname: str, ns: Namespace, tmp_dir: str) -> subpro
6868
'--worker-args', worker_args]
6969

7070
env = dict(os.environ)
71-
env['TMPDIR'] = tmp_dir
72-
env['TEMPDIR'] = tmp_dir
71+
if tmp_dir is not None:
72+
env['TMPDIR'] = tmp_dir
73+
env['TEMP'] = tmp_dir
74+
env['TMP'] = tmp_dir
7375

7476
# Running the child from the same working directory as regrtest's original
7577
# invocation ensures that TEMPDIR for the child is the same when
@@ -271,17 +273,21 @@ def _run_process(self, test_name: str, tmp_dir: str) -> tuple[int, str, str]:
271273
self.current_test_name = None
272274

273275
def _runtest(self, test_name: str) -> MultiprocessResult:
274-
# gh-93353: Check for leaked temporary files in the parent process,
275-
# since the deletion of temporary files can happen late during
276-
# Python finalization: too late for libregrtest.
277-
tmp_dir = os.getcwd() + '_tmpdir'
278-
tmp_dir = os.path.abspath(tmp_dir)
279-
try:
280-
os.mkdir(tmp_dir)
281-
retcode, stdout = self._run_process(test_name, tmp_dir)
282-
finally:
283-
tmp_files = os.listdir(tmp_dir)
284-
os_helper.rmtree(tmp_dir)
276+
if self.ns.use_mp == 1:
277+
# gh-93353: Check for leaked temporary files in the parent process,
278+
# since the deletion of temporary files can happen late during
279+
# Python finalization: too late for libregrtest.
280+
tmp_dir = os.getcwd() + '_tmpdir'
281+
tmp_dir = os.path.abspath(tmp_dir)
282+
try:
283+
os.mkdir(tmp_dir)
284+
retcode, stdout = self._run_process(test_name, tmp_dir)
285+
finally:
286+
tmp_files = os.listdir(tmp_dir)
287+
os_helper.rmtree(tmp_dir)
288+
else:
289+
retcode, stdout = self._run_process(test_name, None)
290+
tmp_files = ()
285291

286292
if retcode is None:
287293
return self.mp_result_error(Timeout(test_name), stdout)
@@ -306,8 +312,8 @@ def _runtest(self, test_name: str) -> MultiprocessResult:
306312

307313
if tmp_files:
308314
msg = (f'\n\n'
309-
f'Warning -- Test leaked temporary files ({len(tmp_files)}): '
310-
f'{", ".join(sorted(tmp_files))}')
315+
f'Warning -- {test_name} leaked temporary files '
316+
f'({len(tmp_files)}): {", ".join(sorted(tmp_files))}')
311317
stdout += msg
312318
if isinstance(result, Passed):
313319
result = EnvChanged.from_passed(result)

Lib/test/test_regrtest.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,9 @@ def test_leak_tmp_file(self):
13751375
self.check_executed_tests(output, [testname],
13761376
env_changed=[testname],
13771377
fail_env_changed=True)
1378-
self.assertIn("Warning -- Test leaked temporary files (1): mytmpfile", output)
1378+
self.assertIn(f"Warning -- {testname} leaked temporary "
1379+
f"files (1): mytmpfile",
1380+
output)
13791381

13801382

13811383
class TestUtils(unittest.TestCase):

0 commit comments

Comments
 (0)