rez.package_test#

class rez.package_test.PackageTestRunner#

Bases: object

Object for running a package’s tests.

This runs the tests listed in the package’s “tests” attribute.

An example tests entry in a package.py might look like this:

tests = {
    "unit": "python -m unittest -s {root}/tests",
    "CI": {
        "command": "python {root}/ci_tests/main.py",
        "requires": ["maya-2017"],
        "replace": True
    }
}

By default tests are run in an environment containing the current package.

If a test entry is just a string, then it is treated as the test command. If a dict, the “command” string is the command, and the “requires” list is added to the test env.

Command strings automatically expand references such as {root}, much as happens in a commands function.

Commands can also be a list - in this case, the test process is launched directly, rather than interpreted via a shell.

__init__(package_request, use_current_env=False, extra_package_requests=None, package_paths=None, stdout=None, stderr=None, verbose=0, dry_run=False, stop_on_fail=False, cumulative_test_results=None, **context_kwargs)#

Create a package tester.

Parameters:
  • package_request (str or PackageRequest) – The package to test.

  • use_current_env (bool) – If True, run the test directly in the current rez-resolved environment, if there is one, and if it contains packages that meet the test’s requirements.

  • extra_package_requests (list[str] or PackageRequest) – Extra requests, these are appended to the test environment.

  • package_paths – List of paths to search for pkgs, defaults to packages_path.

  • stdout (IO) – Defaults to sys.stdout.

  • stderr (IO) – Defaults to sys.stderr.

  • verbose (int) – Verbose mode (valid values: 0, 1, 2)

  • dry_run (bool) – If True, do everything except actually run tests.

  • cumulative_test_results (PackageTestResults) – If supplied, test run results can be stored across multiple runners.

  • context_kwargs (dict[Any, Any]) – Extra arguments which are passed to the ResolvedContext instances used to run the tests within. Ignored if use_current_env is True.

get_package()#

Get the target package.

Returns:

Package to run tests on.

Return type:

Package

classmethod get_package_test_names(package, run_on=None, ran_once=None)#

Get the names of tests in the given package.

Parameters:
  • run_on (list of str) – If provided, only include tests with run_on tags that overlap with the given list.

  • ran_once (list of str) – If provided, skip tests that are in this list, and are configured for on_variants=False (ie, just run the test on one variant).

Returns:

Test names.

Return type:

List of str

get_test_names(run_on=None)#

Get the names of tests in this package.

Parameters:

run_on (list of str) – If provided, only include tests with run_on tags that overlap with the given list.

Returns:

Test names.

Return type:

List of str

property num_tests#

Get the number of tests, regardless of stats.

property num_success#

Get the number of successful test runs.

property num_failed#

Get the number of failed test runs.

property num_skipped#

Get the number of skipped test runs.

run_test(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.

Parameters:
  • 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:

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.

Return type:

int

print_summary()#
class rez.package_test.PackageTestResults#

Bases: object

Contains results of running tests with a PackageTestRunner.

Use this class (and pass it to the PackageTestRunner constructor) if you need to gather test run results from separate runners, and display them in a single table.

valid_statuses = ('success', 'failed', 'skipped')#
__init__()#
property num_tests#

Get the number of tests, regardless of stats.

property num_success#

Get the number of successful test runs.

property num_failed#

Get the number of failed test runs.

property num_skipped#

Get the number of skipped test runs.

add_test_result(test_name, variant, status, description)#
print_summary()#