Add a CLI argument that takes fnmatch(3)-style patterns as value and can be specified many times. Only tests that match the pattern will be executed. This argument is passed to unittest.main which takes the same argument.
Signed-off-by: Manos Pitsidianakis <manos.pitsidiana...@linaro.org> --- tests/functional/qemu_test/testcase.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu_test/testcase.py index bfee6638edf6f9853ead1e3809ae3c9152089406..e137c05baf91f6f88d6228d86d98aa9498797382 100644 --- a/tests/functional/qemu_test/testcase.py +++ b/tests/functional/qemu_test/testcase.py @@ -16,6 +16,7 @@ import os from pathlib import Path import pycotap +import itertools import shutil from subprocess import run import sys @@ -55,6 +56,14 @@ def parse_args(test_name: str) -> argparse.Namespace: action="store_true", help="List all tests that would be executed and exit.", ) + parser.add_argument( + "-k", + dest="test_name_patterns", + action="append", + type=str, + help="Only run tests which match the given substring. " + "This argument is passed to unittest.main verbatim.", + ) return parser.parse_args() @@ -300,8 +309,16 @@ def main(): tr = pycotap.TAPTestRunner(message_log = pycotap.LogMode.LogToError, test_output_log = pycotap.LogMode.LogToError) - res = unittest.main(module = None, testRunner = tr, exit = False, - argv=["__dummy__", path]) + argv = ["__dummy__", path] + ( + list( + itertools.chain.from_iterable( + ["-k", x] for x in args.test_name_patterns + ) + ) + if args.test_name_patterns + else [] + ) + res = unittest.main(module=None, testRunner=tr, exit=False, argv=argv) for (test, message) in res.result.errors + res.result.failures: if hasattr(test, "log_filename"): -- 2.47.2