diff --git a/test_run.py b/test_run.py index 86a8810..88c0639 100755 --- a/test_run.py +++ b/test_run.py @@ -44,13 +44,37 @@ def retrieve_test_list(config_file=f"{PARENT_DIR}/.buildkite/test_description.js """ ) parser = ArgumentParser(description=help_text, formatter_class=RawTextHelpFormatter) - parser.parse_args() + parser.add_argument( + "-l", + "--list-tests", + action="store_true", + default=False, + help="List available tests", + ) + parser.add_argument( + "tests", + nargs="*", + help="The tests to run. If none are specified run all the available tests.", + ) + args = parser.parse_args() test_config = retrieve_test_list() + for test in test_config["tests"]: + name = test["test_name"] + + if len(args.tests) > 0: + if name not in args.tests: + continue + command = test["command"] command = command.replace("{target_platform}", platform.machine()) - test_func = make_test_function(command) - setattr(TestsContainer, "test_{}".format(test["test_name"]), test_func) + if args.list_tests: + print(f"{name}: {command}") + else: + test_func = make_test_function(command) + setattr(TestsContainer, f"test_{name}", test_func) - unittest.main(verbosity=2) + if not args.list_tests: + tests_suite = unittest.TestLoader().loadTestsFromTestCase(TestsContainer) + unittest.TextTestRunner(verbosity=2).run(tests_suite)