Skip to content

Commit bca5034

Browse files
committed
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 <stijn@ignitron.net>
1 parent 03e0651 commit bca5034

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

tests/run-tests.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,19 @@ def main():
12221222
if args.platform == "webassembly":
12231223
test_extensions += ("*.js", "*.mjs")
12241224

1225-
if args.test_dirs is None:
1225+
if args.test_dirs is not None:
1226+
# Run tests from given directories though if user explicitly passes this directory as argument
1227+
# still do the normal test discovery to be consistent with running from within this directory.
1228+
main_tests_dir = os.path.realpath(base_path())
1229+
all_test_dirs = [
1230+
test_dir for test_dir in args.test_dirs if os.path.realpath(test_dir) != main_tests_dir
1231+
]
1232+
main_tests_dir_in_args = len(args.test_dirs) != len(all_test_dirs)
1233+
else:
1234+
all_test_dirs = []
1235+
main_tests_dir_in_args = False
1236+
1237+
if args.test_dirs is None or main_tests_dir_in_args:
12261238
test_dirs = (
12271239
"basics",
12281240
"micropython",
@@ -1246,13 +1258,13 @@ def main():
12461258
test_dirs += ("import",)
12471259
if args.build != "minimal":
12481260
test_dirs += ("cmdline", "io")
1249-
else:
1250-
# run tests from these directories
1251-
test_dirs = args.test_dirs
1261+
1262+
all_test_dirs.extend(base_path(test_dir) for test_dir in test_dirs)
1263+
12521264
tests = sorted(
12531265
test_file
12541266
for test_files in (
1255-
glob(os.path.join(dir, ext)) for dir in test_dirs for ext in test_extensions
1267+
glob(os.path.join(dir, ext)) for dir in all_test_dirs for ext in test_extensions
12561268
)
12571269
for test_file in test_files
12581270
)

0 commit comments

Comments
 (0)