From 8f1ec165dcf84d2cc36490f4c44909c2d4187ea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Mon, 17 Jul 2023 19:47:00 +0100 Subject: [PATCH 1/3] test_run.py: hoist name from test config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ...and use this is a format string. This will help with later re-factoring. Signed-off-by: Alex Bennée --- test_run.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test_run.py b/test_run.py index 86a8810..a45a6d2 100755 --- a/test_run.py +++ b/test_run.py @@ -48,9 +48,10 @@ def retrieve_test_list(config_file=f"{PARENT_DIR}/.buildkite/test_description.js test_config = retrieve_test_list() for test in test_config["tests"]: + name = test["test_name"] 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) + setattr(TestsContainer, f"test_{name}", test_func) unittest.main(verbosity=2) From 370add9ed189b6182ef921d4edd70547af2cd69e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Mon, 17 Jul 2023 13:39:25 +0100 Subject: [PATCH 2/3] test_run.py: make it easy to see all the tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rather than make developers dive into the json configuration provide a little introspection command line to list the available tests. Signed-off-by: Alex Bennée --- test_run.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/test_run.py b/test_run.py index a45a6d2..19eaf79 100755 --- a/test_run.py +++ b/test_run.py @@ -44,14 +44,26 @@ 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", + ) + args = parser.parse_args() test_config = retrieve_test_list() + for test in test_config["tests"]: name = test["test_name"] command = test["command"] command = command.replace("{target_platform}", platform.machine()) - test_func = make_test_function(command) - setattr(TestsContainer, f"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: + unittest.main(verbosity=2) From 09f4273de7540462b5ebdab26b68db9080312691 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Benn=C3=A9e?= Date: Mon, 17 Jul 2023 19:54:34 +0100 Subject: [PATCH 3/3] test_run.py: allow specifying of individual tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the user specifies any tests on the command line then only run those. Signed-off-by: Alex Bennée --- test_run.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test_run.py b/test_run.py index 19eaf79..88c0639 100755 --- a/test_run.py +++ b/test_run.py @@ -51,12 +51,22 @@ def retrieve_test_list(config_file=f"{PARENT_DIR}/.buildkite/test_description.js 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()) if args.list_tests: @@ -66,4 +76,5 @@ def retrieve_test_list(config_file=f"{PARENT_DIR}/.buildkite/test_description.js setattr(TestsContainer, f"test_{name}", test_func) if not args.list_tests: - unittest.main(verbosity=2) + tests_suite = unittest.TestLoader().loadTestsFromTestCase(TestsContainer) + unittest.TextTestRunner(verbosity=2).run(tests_suite)