Skip to content

Commit

Permalink
Allow user to pass extra arguments to underlying rez test command (#665
Browse files Browse the repository at this point in the history
…).

Signed-off-by: Ben <bhawkyard1@gmail.com>
  • Loading branch information
bhawkyard1 committed Aug 27, 2023
1 parent aeade21 commit be318a2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/rez/cli/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
},
"status": {},
"suite": {},
"test": {},
"test": {
"arg_mode": "grouped"
},
"view": {},
"yaml2py": {},
"bundle": {},
Expand Down
10 changes: 9 additions & 1 deletion src/rez/cli/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion src/rez/package_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,20 +232,24 @@ 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
same requirements, the contexts will be reused.
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

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit be318a2

Please sign in to comment.