From e08e3d796ca5f37eec2644db7a1ae99dcc8ae024 Mon Sep 17 00:00:00 2001 From: stijn Date: Wed, 11 Feb 2026 11:42:41 +0100 Subject: [PATCH] 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 --- tests/run-tests.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/run-tests.py b/tests/run-tests.py index c21f6df0a3..3f876e3ff4 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -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