From be318a2de2b0f2462949fb392f1add7d1152f01d Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 18 Aug 2023 16:55:03 +0100 Subject: [PATCH] Allow user to pass extra arguments to underlying rez test command (#665). Signed-off-by: Ben --- src/rez/cli/_util.py | 4 +++- src/rez/cli/test.py | 10 +++++++++- src/rez/package_test.py | 9 ++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/rez/cli/_util.py b/src/rez/cli/_util.py index 1fb750504e..45910258e5 100644 --- a/src/rez/cli/_util.py +++ b/src/rez/cli/_util.py @@ -59,7 +59,9 @@ }, "status": {}, "suite": {}, - "test": {}, + "test": { + "arg_mode": "grouped" + }, "view": {}, "yaml2py": {}, "bundle": {}, diff --git a/src/rez/cli/test.py b/src/rez/cli/test.py index cf58d153ab..b92e967f74 100644 --- a/src/rez/cli/test.py +++ b/src/rez/cli/test.py @@ -64,6 +64,14 @@ def command(opts, parser, extra_arg_groups=None): pkg_paths = opts.paths.split(os.pathsep) pkg_paths = [os.path.expanduser(x) for x in pkg_paths if x] + if extra_arg_groups: + if not opts.TEST or len(opts.TEST) > 1: + parser.error( + "You can only pass extra arguments to a single, specified test. " + "Please rerun the command and specify a single test to run." + ) + extra_arg_groups = extra_arg_groups[0] + # run test(s) runner = PackageTestRunner( package_request=opts.PKG, @@ -107,7 +115,7 @@ def command(opts, parser, extra_arg_groups=None): for test_name in run_test_names: if not runner.stopped_on_fail: - ret = runner.run_test(test_name) + ret = runner.run_test(test_name, extra_test_args=extra_arg_groups) if ret and not exitcode: exitcode = ret diff --git a/src/rez/package_test.py b/src/rez/package_test.py index 045e2a6293..d40a6c4220 100644 --- a/src/rez/package_test.py +++ b/src/rez/package_test.py @@ -232,7 +232,7 @@ def num_skipped(self): """ return self.test_results.num_skipped - def run_test(self, test_name): + def run_test(self, test_name, extra_test_args=None): """Run a test. Runs the test in its correct environment. Note that if tests share the @@ -240,12 +240,16 @@ def run_test(self, test_name): Args: test_name (str): Name of test to run. + extra_test_args (list of str): Any extra arguments that we want to + pass to the test command. Returns: int: Exit code of first failed test, or 0 if none failed. If the first test to fail did so because it was not able to run (eg its environment could not be configured), -1 is returned. """ + if extra_test_args is None: + extra_test_args = [] package = self.get_package() exitcode = 0 @@ -394,6 +398,9 @@ def run_test(self, test_name): else: command = map(variant.format, command) + if extra_test_args: + command = "{} {}".format(command, " ".join(extra_test_args)) + # run the test in the context if self.verbose: if self.verbose > 1: