rez.package_test

class rez.package_test.PackageTestResults[source]

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.

add_test_result(test_name, variant, status, description)[source]
property num_failed

Get the number of failed test runs.

property num_skipped

Get the number of skipped test runs.

property num_success

Get the number of successful test runs.

property num_tests

Get the number of tests, regardless of stats.

print_summary()[source]
valid_statuses = ('success', 'failed', 'skipped')
class rez.package_test.PackageTestRunner(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)[source]

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.

get_package()[source]

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)[source]

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)[source]

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_failed

Get the number of failed test runs.

property num_skipped

Get the number of skipped test runs.

property num_success

Get the number of successful test runs.

property num_tests

Get the number of tests, regardless of stats.

print_summary()[source]
run_test(test_name)[source]

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.

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