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>
This commit is contained in:
stijn
2026-02-11 11:42:41 +01:00
committed by Damien George
parent 7b9163372d
commit e08e3d796c

View File

@@ -841,8 +841,20 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1):
skip_tests = [os.path.realpath(base_path(skip_test)) for skip_test in skip_tests]
def run_one_test(test_file):
test_file = test_file.replace("\\", "/")
test_file_abspath = os.path.abspath(test_file).replace("\\", "/")
# If test_file is one of our own tests always make it relative to our tests/ dir and
# otherwise use the abosulte path, irregardless of actual path passed,
# such that display and result output is always the same.
try:
test_file_relpath = os.path.relpath(test_file, start=base_path())
if not test_file_relpath.startswith(".."):
test_file = test_file_relpath
else:
test_file = test_file_abspath
except ValueError:
# Path on different drive on Windows.
test_file = test_file_abspath
test_file = test_file.replace("\\", "/")
if args.filters:
# Default verdict is the opposite of the first action