[Python-checkins] gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)

tiran webhook-mailer at python.org
Tue Jun 14 12:04:59 EDT 2022


https://github.com/python/cpython/commit/36934a16e86f34d69ba2d41630fb5b4d06d59cff
commit: 36934a16e86f34d69ba2d41630fb5b4d06d59cff
branch: main
author: Victor Stinner <vstinner at python.org>
committer: tiran <christian at python.org>
date: 2022-06-14T18:04:53+02:00
summary:

gh-93353: Fix regrtest for -jN with N >= 2 (GH-93813)

files:
M Lib/test/libregrtest/runtest_mp.py
M Lib/test/test_regrtest.py

diff --git a/Lib/test/libregrtest/runtest_mp.py b/Lib/test/libregrtest/runtest_mp.py
index c6190e5d22d50..a901b582f27da 100644
--- a/Lib/test/libregrtest/runtest_mp.py
+++ b/Lib/test/libregrtest/runtest_mp.py
@@ -68,8 +68,10 @@ def run_test_in_subprocess(testname: str, ns: Namespace, tmp_dir: str) -> subpro
            '--worker-args', worker_args]
 
     env = dict(os.environ)
-    env['TMPDIR'] = tmp_dir
-    env['TEMPDIR'] = tmp_dir
+    if tmp_dir is not None:
+        env['TMPDIR'] = tmp_dir
+        env['TEMP'] = tmp_dir
+        env['TMP'] = tmp_dir
 
     # Running the child from the same working directory as regrtest's original
     # 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]:
             self.current_test_name = None
 
     def _runtest(self, test_name: str) -> MultiprocessResult:
-        # gh-93353: Check for leaked temporary files in the parent process,
-        # since the deletion of temporary files can happen late during
-        # Python finalization: too late for libregrtest.
-        tmp_dir = os.getcwd() + '_tmpdir'
-        tmp_dir = os.path.abspath(tmp_dir)
-        try:
-            os.mkdir(tmp_dir)
-            retcode, stdout = self._run_process(test_name, tmp_dir)
-        finally:
-            tmp_files = os.listdir(tmp_dir)
-            os_helper.rmtree(tmp_dir)
+        if self.ns.use_mp == 1:
+            # gh-93353: Check for leaked temporary files in the parent process,
+            # since the deletion of temporary files can happen late during
+            # Python finalization: too late for libregrtest.
+            tmp_dir = os.getcwd() + '_tmpdir'
+            tmp_dir = os.path.abspath(tmp_dir)
+            try:
+                os.mkdir(tmp_dir)
+                retcode, stdout = self._run_process(test_name, tmp_dir)
+            finally:
+                tmp_files = os.listdir(tmp_dir)
+                os_helper.rmtree(tmp_dir)
+        else:
+            retcode, stdout = self._run_process(test_name, None)
+            tmp_files = ()
 
         if retcode is None:
             return self.mp_result_error(Timeout(test_name), stdout)
@@ -306,8 +312,8 @@ def _runtest(self, test_name: str) -> MultiprocessResult:
 
         if tmp_files:
             msg = (f'\n\n'
-                   f'Warning -- Test leaked temporary files ({len(tmp_files)}): '
-                   f'{", ".join(sorted(tmp_files))}')
+                   f'Warning -- {test_name} leaked temporary files '
+                   f'({len(tmp_files)}): {", ".join(sorted(tmp_files))}')
             stdout += msg
             if isinstance(result, Passed):
                 result = EnvChanged.from_passed(result)
diff --git a/Lib/test/test_regrtest.py b/Lib/test/test_regrtest.py
index 5c072ea331d74..93c0cae1473a0 100644
--- a/Lib/test/test_regrtest.py
+++ b/Lib/test/test_regrtest.py
@@ -1375,7 +1375,9 @@ def test_leak_tmp_file(self):
         self.check_executed_tests(output, [testname],
                                   env_changed=[testname],
                                   fail_env_changed=True)
-        self.assertIn("Warning -- Test leaked temporary files (1): mytmpfile", output)
+        self.assertIn(f"Warning -- {testname} leaked temporary "
+                      f"files (1): mytmpfile",
+                      output)
 
 
 class TestUtils(unittest.TestCase):



More information about the Python-checkins mailing list