Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b03f2c

Browse files
committed
Inherit interpreter flags in parallel testing
1 parent 9a6692f commit 1b03f2c

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

Lib/test/regrtest.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,6 @@ def main(tests=None, testdir=None, verbose=0, quiet=False,
391391
usage("-T and -j don't go together!")
392392
if use_mp and findleaks:
393393
usage("-l and -j don't go together!")
394-
if use_mp and max(sys.flags):
395-
# TODO: inherit the environment and the flags
396-
print("Warning: flags and environment variables are ignored with -j option")
397394

398395
good = []
399396
bad = []
@@ -534,6 +531,8 @@ def tests_and_args():
534531
)
535532
yield (test, args_tuple)
536533
pending = tests_and_args()
534+
opt_args = support.args_from_interpreter_flags()
535+
base_cmd = [sys.executable] + opt_args + ['-m', 'test.regrtest']
537536
def work():
538537
# A worker thread.
539538
try:
@@ -544,8 +543,7 @@ def work():
544543
output.put((None, None, None, None))
545544
return
546545
# -E is needed by some tests, e.g. test_import
547-
popen = Popen([sys.executable, '-E', '-m', 'test.regrtest',
548-
'--slaveargs', json.dumps(args_tuple)],
546+
popen = Popen(base_cmd + ['--slaveargs', json.dumps(args_tuple)],
549547
stdout=PIPE, stderr=PIPE,
550548
universal_newlines=True,
551549
close_fds=(os.name != 'nt'))

Lib/test/support.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,3 +1327,22 @@ def strip_python_stderr(stderr):
13271327
"""
13281328
stderr = re.sub(br"\[\d+ refs\]\r?\n?$", b"", stderr).strip()
13291329
return stderr
1330+
1331+
def args_from_interpreter_flags():
1332+
"""Return a list of command-line arguments reproducing the current
1333+
settings in sys.flags."""
1334+
flag_opt_map = {
1335+
'bytes_warning': 'b',
1336+
'dont_write_bytecode': 'B',
1337+
'ignore_environment': 'E',
1338+
'no_user_site': 's',
1339+
'no_site': 'S',
1340+
'optimize': 'O',
1341+
'verbose': 'v',
1342+
}
1343+
args = []
1344+
for flag, opt in flag_opt_map.items():
1345+
v = getattr(sys.flags, flag)
1346+
if v > 0:
1347+
args.append('-' + opt * v)
1348+
return args

0 commit comments

Comments
 (0)