Skip to content

Commit b8098df

Browse files
stinosdpgeorge
authored andcommitted
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 ff4d4bf commit b8098df

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

tests/run-tests.py

Lines changed: 22 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+
all_test_dirs = []
1226+
main_tests_dir_in_args = None
1227+
if args.test_dirs is not None:
1228+
# Run tests from given directories though if user explicitly passes this directory as argument
1229+
# still do the normal test discovery to be consistent with running from within this directory.
1230+
main_tests_dir = os.path.realpath(base_path())
1231+
for test_dir in args.test_dirs:
1232+
if os.path.realpath(test_dir) == main_tests_dir:
1233+
main_tests_dir_in_args = test_dir
1234+
else:
1235+
all_test_dirs.append(test_dir)
1236+
1237+
if args.test_dirs is None or main_tests_dir_in_args is not None:
12261238
test_dirs = (
12271239
"basics",
12281240
"micropython",
@@ -1246,13 +1258,18 @@ 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(
1263+
test_dir
1264+
if main_tests_dir_in_args is None
1265+
else os.path.join(main_tests_dir_in_args, test_dir)
1266+
for test_dir in test_dirs
1267+
)
1268+
12521269
tests = sorted(
12531270
test_file
12541271
for test_files in (
1255-
glob(os.path.join(dir, ext)) for dir in test_dirs for ext in test_extensions
1272+
glob(os.path.join(dir, ext)) for dir in all_test_dirs for ext in test_extensions
12561273
)
12571274
for test_file in test_files
12581275
)

0 commit comments

Comments
 (0)