Skip to content

Commit 9123b67

Browse files
committed
tests/run-tests: Use -BS flags when running CPython.
The use of -S ensures that only the CPython standard library is accessible, which makes tests run the same regardless of any site-packages that are installed. It also improves start-up time of CPython, reducing the overall time spent running the test suite. tests/basics/containment.py is updated to work around issue with old Python versions not being able to str-format a dict-keys object, which becomes apparent when -S is used. Signed-off-by: Damien George <[email protected]>
1 parent c8ade2b commit 9123b67

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

tests/basics/containment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# sets, see set_containment
22
for i in 1, 2:
33
for o in {1:2}, {1:2}.keys():
4-
print("{} in {}: {}".format(i, o, i in o))
5-
print("{} not in {}: {}".format(i, o, i not in o))
4+
print("{} in {}: {}".format(i, str(o), i in o))
5+
print("{} not in {}: {}".format(i, str(o), i not in o))
66

77
haystack = "supercalifragilistc"
88
for needle in [haystack[i:] for i in range(len(haystack))]:

tests/run-tests

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ else:
2626
CPYTHON3 = os.getenv('MICROPY_CPYTHON3', 'python3')
2727
MICROPYTHON = os.getenv('MICROPY_MICROPYTHON', base_path('../ports/unix/micropython'))
2828

29+
# Use CPython options to not save .pyc files, to only access the core standard library
30+
# (not site packages which may clash with u-module names), and improve start up time.
31+
CPYTHON3_CMD = [CPYTHON3, "-BS"]
32+
2933
# mpy-cross is only needed if --via-mpy command-line arg is passed
3034
MPYCROSS = os.getenv('MICROPY_MPYCROSS', base_path('../mpy-cross/mpy-cross'))
3135

@@ -319,7 +323,7 @@ def run_tests(pyb, tests, args, result_dir):
319323
upy_float_precision = int(upy_float_precision)
320324
has_complex = run_feature_check(pyb, args, base_path, 'complex.py') == b'complex\n'
321325
has_coverage = run_feature_check(pyb, args, base_path, 'coverage.py') == b'coverage\n'
322-
cpy_byteorder = subprocess.check_output([CPYTHON3, base_path('feature_check/byteorder.py')])
326+
cpy_byteorder = subprocess.check_output(CPYTHON3_CMD + [base_path('feature_check/byteorder.py')])
323327
skip_endian = (upy_byteorder != cpy_byteorder)
324328

325329
# These tests don't test slice explicitly but rather use it to perform the test
@@ -498,7 +502,7 @@ def run_tests(pyb, tests, args, result_dir):
498502
else:
499503
# run CPython to work out expected output
500504
try:
501-
output_expected = subprocess.check_output([CPYTHON3, '-B', test_file])
505+
output_expected = subprocess.check_output(CPYTHON3_CMD + [test_file])
502506
if args.write_exp:
503507
with open(test_file_expected, 'wb') as f:
504508
f.write(output_expected)

0 commit comments

Comments
 (0)