summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2020-09-24 12:03:30 +1000
committerDamien George <damien@micropython.org>2020-09-25 12:27:23 +1000
commit9123b67d641ba708a4ea3e5cd50665f0a73c6c8a (patch)
tree390fb90fe6413f2c435eee599515b261bdb332e2
parentc8ade2bd7f5d0e089098bcc07eb77a770f3da726 (diff)
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 <damien@micropython.org>
-rw-r--r--tests/basics/containment.py4
-rwxr-xr-xtests/run-tests8
2 files changed, 8 insertions, 4 deletions
diff --git a/tests/basics/containment.py b/tests/basics/containment.py
index 4c94a9bae..24317ddd2 100644
--- a/tests/basics/containment.py
+++ b/tests/basics/containment.py
@@ -1,8 +1,8 @@
# sets, see set_containment
for i in 1, 2:
for o in {1:2}, {1:2}.keys():
- print("{} in {}: {}".format(i, o, i in o))
- print("{} not in {}: {}".format(i, o, i not in o))
+ print("{} in {}: {}".format(i, str(o), i in o))
+ print("{} not in {}: {}".format(i, str(o), i not in o))
haystack = "supercalifragilistc"
for needle in [haystack[i:] for i in range(len(haystack))]:
diff --git a/tests/run-tests b/tests/run-tests
index a7b88ecdd..eebc8c425 100755
--- a/tests/run-tests
+++ b/tests/run-tests
@@ -26,6 +26,10 @@ else:
CPYTHON3 = os.getenv('MICROPY_CPYTHON3', 'python3')
MICROPYTHON = os.getenv('MICROPY_MICROPYTHON', base_path('../ports/unix/micropython'))
+# Use CPython options to not save .pyc files, to only access the core standard library
+# (not site packages which may clash with u-module names), and improve start up time.
+CPYTHON3_CMD = [CPYTHON3, "-BS"]
+
# mpy-cross is only needed if --via-mpy command-line arg is passed
MPYCROSS = os.getenv('MICROPY_MPYCROSS', base_path('../mpy-cross/mpy-cross'))
@@ -319,7 +323,7 @@ def run_tests(pyb, tests, args, result_dir):
upy_float_precision = int(upy_float_precision)
has_complex = run_feature_check(pyb, args, base_path, 'complex.py') == b'complex\n'
has_coverage = run_feature_check(pyb, args, base_path, 'coverage.py') == b'coverage\n'
- cpy_byteorder = subprocess.check_output([CPYTHON3, base_path('feature_check/byteorder.py')])
+ cpy_byteorder = subprocess.check_output(CPYTHON3_CMD + [base_path('feature_check/byteorder.py')])
skip_endian = (upy_byteorder != cpy_byteorder)
# 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):
else:
# run CPython to work out expected output
try:
- output_expected = subprocess.check_output([CPYTHON3, '-B', test_file])
+ output_expected = subprocess.check_output(CPYTHON3_CMD + [test_file])
if args.write_exp:
with open(test_file_expected, 'wb') as f:
f.write(output_expected)