From b8098df3a7819111ae6ea3a3c154c070f3b5d0e7 Mon Sep 17 00:00:00 2001 From: stijn Date: Mon, 9 Feb 2026 13:58:16 +0100 Subject: [PATCH] tests/run-tests.py: Use normal discovery if tests dir passed explicitly. Scan the --test-dirs argument for the main tests directory being passed and if so do the same thing as if running from within that main test directory. In practice this makes the following (which used to counterintuitively try and fail to run the .py files in the tests/ directory itself) >python micropython/tests/run-tests.py -d micropython/tests do the same thing as >cd micropython/tests >python ./run-tests.py which is logical and convenient. Signed-off-by: stijn --- tests/run-tests.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/tests/run-tests.py b/tests/run-tests.py index c624012afe..c21f6df0a3 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -1222,7 +1222,19 @@ the last matching regex is used: if args.platform == "webassembly": test_extensions += ("*.js", "*.mjs") - if args.test_dirs is None: + all_test_dirs = [] + main_tests_dir_in_args = None + if args.test_dirs is not None: + # Run tests from given directories though if user explicitly passes this directory as argument + # still do the normal test discovery to be consistent with running from within this directory. + main_tests_dir = os.path.realpath(base_path()) + for test_dir in args.test_dirs: + if os.path.realpath(test_dir) == main_tests_dir: + main_tests_dir_in_args = test_dir + else: + all_test_dirs.append(test_dir) + + if args.test_dirs is None or main_tests_dir_in_args is not None: test_dirs = ( "basics", "micropython", @@ -1246,13 +1258,18 @@ the last matching regex is used: test_dirs += ("import",) if args.build != "minimal": test_dirs += ("cmdline", "io") - else: - # run tests from these directories - test_dirs = args.test_dirs + + all_test_dirs.extend( + test_dir + if main_tests_dir_in_args is None + else os.path.join(main_tests_dir_in_args, test_dir) + for test_dir in test_dirs + ) + tests = sorted( test_file for test_files in ( - glob(os.path.join(dir, ext)) for dir in test_dirs for ext in test_extensions + glob(os.path.join(dir, ext)) for dir in all_test_dirs for ext in test_extensions ) for test_file in test_files )