Skip to content

Commit 9842f6a

Browse files
committed
Use tempfile in the parent process
1 parent fe0fe87 commit 9842f6a

3 files changed

Lines changed: 36 additions & 20 deletions

File tree

‎runtests.py‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import os.path
1313
import shutil
1414
import sys
15+
import tempfile
1516
import time
1617
from concurrent.futures import ThreadPoolExecutor
1718

@@ -51,10 +52,10 @@
5152
)
5253

5354

54-
def get_test_command(executable, verbose):
55+
def get_test_command(executable, verbose, build_dir):
5556
# Don't use realpath() for the executed command to support virtual
5657
# environments
57-
cmd = [executable, TEST_COMPAT]
58+
cmd = [executable, TEST_COMPAT, build_dir]
5859
if verbose:
5960
cmd.append('-v')
6061
return cmd
@@ -90,8 +91,9 @@ def run_tests_parallel(args):
9091
jobs.append(executable)
9192

9293
def worker(executable):
93-
cmd = get_test_command(executable, args.verbose)
94-
return get_output(cmd)
94+
with tempfile.TemporaryDirectory() as build_dir:
95+
cmd = get_test_command(executable, args.verbose, build_dir)
96+
return get_output(cmd)
9597

9698
if hasattr(os, 'process_cpu_count'):
9799
max_workers = os.process_cpu_count()
@@ -127,6 +129,13 @@ def test_upgrade_pythoncapi(args):
127129
print()
128130

129131

132+
def test_current_version(args):
133+
with tempfile.TemporaryDirectory() as build_dir:
134+
cmd = get_test_command(sys.executable, args.verbose, build_dir)
135+
run_command(cmd)
136+
print()
137+
138+
130139
def main():
131140
start_time = time.perf_counter()
132141
args = parse_args()
@@ -136,9 +145,7 @@ def main():
136145
if not args.current:
137146
run_tests_parallel(args)
138147
else:
139-
cmd = get_test_command(sys.executable, args.verbose)
140-
run_command(cmd)
141-
print()
148+
test_current_version(args)
142149

143150
dt = time.perf_counter() - start_time
144151
print(f"Total time: {dt:.1f} seconds")

‎tests/test_pythoncapi_compat.py‎

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
python3 run_tests.py
88
python3 run_tests.py -v # verbose mode
99
"""
10+
import argparse
1011
import faulthandler
1112
import gc
1213
import os.path
1314
import shutil
1415
import subprocess
1516
import sys
1617
import sysconfig
17-
import tempfile
1818

1919
# test.utils
2020
import setup
@@ -202,28 +202,36 @@ def test_func():
202202
msg += " (no reference leak detected)"
203203
print(msg)
204204

205+
# Unload the extension module
206+
testmod = None
207+
del sys.modules[module_name]
208+
209+
210+
def parse_args():
211+
parser = argparse.ArgumentParser()
212+
parser.add_argument('-v', '--verbose',
213+
action='store_true') # on/off flag
214+
parser.add_argument('build_dir')
215+
return parser.parse_args()
216+
205217

206218
def main():
207219
global VERBOSE
208-
VERBOSE = ("-v" in sys.argv[1:] or "--verbose" in sys.argv[1:])
209-
210-
if (3, 13) <= sys.version_info <= (3, 13, 0, 'alpha', 4):
211-
print("SKIP Python 3.13 alpha 1..4: not supported!")
212-
return
220+
args = parse_args()
221+
VERBOSE = args.verbose
222+
build_dir = args.build_dir
213223

214-
if faulthandler is not None:
215-
faulthandler.enable()
224+
faulthandler.enable()
216225

217226
src_dir = os.path.dirname(__file__)
218227
if src_dir:
219228
os.chdir(src_dir)
220229

221-
with tempfile.TemporaryDirectory() as build_dir:
222-
build_ext(build_dir)
230+
build_ext(build_dir)
223231

224-
tests = setup.C_TESTS + setup.CXX_TESTS
225-
for module_name, std, limited in tests:
226-
run_tests(build_dir, module_name, std)
232+
tests = setup.C_TESTS + setup.CXX_TESTS
233+
for module_name, std, limited in tests:
234+
run_tests(build_dir, module_name, std)
227235

228236

229237
if __name__ == "__main__":

‎tests/utils.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def _run_command(cmd, **kw):
1010
proc = subprocess.Popen(cmd, **kw)
1111
try:
1212
proc.communicate()
13+
proc.wait()
1314
except:
1415
proc.kill()
1516
proc.wait()

0 commit comments

Comments
 (0)