Skip to content

Commit e08e3d7

Browse files
stinosdpgeorge
authored andcommitted
tests/run-tests.py: Output consistent test file paths.
Test file paths which get passed to the run_tests function can be absolute or relative and with or without leading slash in the latter case, depending on the arguments to run-tests.py, but since that path is used to: - display which tests run - record which tests ran in the results.json - craft the filename for the .exp/.out file for failed tests it is desirable to always use the same file path irregardless of how the user passed the path. In practice this means that all forms of running our own tests like: >python ./run-tests.py -i extmod >python ./run-tests.py -d extmod >python ./run-tests.py -d ./extmod >python ./run-tests.py -d ../tests/extmod >python ./run-tests.py -d /full/path/to/tests/extmod will now consistently all display the tests like pass extmod/time_time_ns.py FAIL extmod/some_failing_test.py and produce output files like results/extmod_some_failing_test.py.exp results/extmod_some_failing_test.py.out instead of displaying/using the exact path as passed. For external tests, meaning not in the tests/ directory, we also want to be consistent so there the choice was made to always use absolute paths. Signed-off-by: stijn <stijn@ignitron.net>
1 parent 7b91633 commit e08e3d7

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

tests/run-tests.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,8 +841,20 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1):
841841
skip_tests = [os.path.realpath(base_path(skip_test)) for skip_test in skip_tests]
842842

843843
def run_one_test(test_file):
844-
test_file = test_file.replace("\\", "/")
845844
test_file_abspath = os.path.abspath(test_file).replace("\\", "/")
845+
# If test_file is one of our own tests always make it relative to our tests/ dir and
846+
# otherwise use the abosulte path, irregardless of actual path passed,
847+
# such that display and result output is always the same.
848+
try:
849+
test_file_relpath = os.path.relpath(test_file, start=base_path())
850+
if not test_file_relpath.startswith(".."):
851+
test_file = test_file_relpath
852+
else:
853+
test_file = test_file_abspath
854+
except ValueError:
855+
# Path on different drive on Windows.
856+
test_file = test_file_abspath
857+
test_file = test_file.replace("\\", "/")
846858

847859
if args.filters:
848860
# Default verdict is the opposite of the first action

0 commit comments

Comments
 (0)