jobs = runtests.get_jobs()
if jobs is not None:
- tests = f'{jobs} tests'
+ tests = count(jobs, 'test')
else:
tests = 'tests'
msg = f"Run {tests} sequentially"
def run_tests(self, selected: TestTuple, tests: TestList | None) -> int:
os.makedirs(self.tmp_dir, exist_ok=True)
- work_dir = get_work_dir(parent_dir=self.tmp_dir)
+ work_dir = get_work_dir(self.tmp_dir)
# Put a timeout on Python exit
with exit_timeout():
import threading
import time
import traceback
-from typing import Literal, TextIO
+from typing import Literal
from test import support
from test.support import os_helper
from .single import PROGRESS_MIN_TIME
from .utils import (
StrPath, StrJSON, TestName, MS_WINDOWS,
- format_duration, print_warning, plural)
+ format_duration, print_warning, count, plural)
from .worker import create_worker_process, USE_PROCESS_GROUP
if MS_WINDOWS:
if worker_json:
result = TestResult.from_json(worker_json)
else:
- err_msg = f"empty JSON"
+ err_msg = "empty JSON"
except Exception as exc:
# gh-101634: Catch UnicodeDecodeError if stdout cannot be
# decoded from encoding
for index in range(1, self.num_workers + 1)]
jobs = self.runtests.get_jobs()
if jobs is not None:
- tests = f'{jobs} tests'
+ tests = count(jobs, 'test')
else:
tests = 'tests'
nworkers = len(self.workers)
MS_WINDOWS = (sys.platform == 'win32')
+WORK_DIR_PREFIX = 'test_python_'
+WORKER_WORK_DIR_PREFIX = f'{WORK_DIR_PREFIX}worker_'
# bpo-38203: Maximum delay in seconds to exit Python (call Py_Finalize()).
# Used to protect against threading._shutdown() hang.
return build
-def get_temp_dir(tmp_dir):
+def get_temp_dir(tmp_dir: StrPath | None = None) -> StrPath:
if tmp_dir:
tmp_dir = os.path.expanduser(tmp_dir)
else:
os.umask(old_mask)
-def get_work_dir(*, parent_dir: StrPath = '', worker: bool = False):
+def get_work_dir(parent_dir: StrPath, worker: bool = False) -> StrPath:
# Define a writable temp dir that will be used as cwd while running
# the tests. The name of the dir includes the pid to allow parallel
# testing (see the -j option).
nounce = os.getpid()
if worker:
- work_dir = 'test_python_worker_{}'.format(nounce)
+ work_dir = WORK_DIR_PREFIX + str(nounce)
else:
- work_dir = 'test_python_{}'.format(nounce)
+ work_dir = WORKER_WORK_DIR_PREFIX + str(nounce)
work_dir += os_helper.FS_NONASCII
- if parent_dir:
- work_dir = os.path.join(parent_dir, work_dir)
+ work_dir = os.path.join(parent_dir, work_dir)
return work_dir
def cleanup_temp_dir(tmp_dir: StrPath):
import glob
- path = os.path.join(glob.escape(tmp_dir), 'test_python_*')
+ path = os.path.join(glob.escape(tmp_dir), WORK_DIR_PREFIX + '*')
print("Cleanup %s directory" % tmp_dir)
for name in glob.glob(path):
if os.path.isdir(name):
import subprocess
import sys
import os
-from typing import TextIO, NoReturn
+from typing import NoReturn
from test import support
from test.support import os_helper
from .single import run_single_test
from .utils import (
StrPath, StrJSON, FilterTuple, MS_WINDOWS,
- get_work_dir, exit_timeout)
+ get_temp_dir, get_work_dir, exit_timeout)
USE_PROCESS_GROUP = (hasattr(os, "setsid") and hasattr(os, "killpg"))
env['TEMP'] = tmp_dir
env['TMP'] = tmp_dir
+ # Emscripten and WASI Python must start in the Python source code directory
+ # to get 'python.js' or 'python.wasm' file. Then worker_process() changes
+ # to a temporary directory created to run tests.
+ work_dir = os_helper.SAVEDCWD
+
# Running the child from the same working directory as regrtest's original
# invocation ensures that TEMPDIR for the child is the same when
# sysconfig.is_python_build() is true. See issue 15300.
stderr=output_fd,
text=True,
close_fds=True,
+ cwd=work_dir,
)
if not MS_WINDOWS:
kwargs['pass_fds'] = [json_fd]
sys.exit(1)
worker_json = sys.argv[1]
- work_dir = get_work_dir(worker=True)
+ tmp_dir = get_temp_dir()
+ work_dir = get_work_dir(tmp_dir, worker=True)
with exit_timeout():
with os_helper.temp_cwd(work_dir, quiet=True):