Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to pass extra arguments to underlying rez test command (REP-001 part 3). #1523

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 11 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,12 @@ def run_test(self, test_name):
else:
command = map(variant.format, command)

if extra_test_args:
if isinstance(command, basestring):
command = "{} {}".format(command, " ".join(map(quote, extra_test_args)))
else:
command = list(map(quote, command)) + list(map(quote, extra_test_args))

# run the test in the context
if self.verbose:
if self.verbose > 1:
Expand Down