runner
Unit tests facility.
Attributes
mlogger = get_logger(__name__)
module-attribute
DEBUG_OKAY_RESULT = 'PASSED'
module-attribute
DEBUG_FAIL_RESULT = 'FAILED'
module-attribute
RESULT_TEST_SUITE_START = '<div class="unittest unitteststart">Test Suite: {suite}</div>'
module-attribute
RESULT_DIV_OKAY = '<div class="unittest unittestokay">:white_heavy_check_mark: PASSED {test}</div>'
module-attribute
RESULT_DIV_FAIL = '<div class="unittest unittestfail">:cross_mark: FAILED {test}</div>'
module-attribute
RESULT_DIV_ERROR = '<div class="unittest unittesterror">:heavy_large_circle: ERROR {test}</div>'
module-attribute
Classes
OutputWriter()
Output writer for tests results.
Source code in pyrevitlib/pyrevit/unittests/runner.py
Methods:
write(output_str)
Prints the results to the output window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_str
|
str
|
Text to output |
required |
PyRevitTestResult(verbosity, suite_name=None)
Bases: TestResult
Pyrevit Test Result.
Also writes JUnit XML when :data:pyrevit.unittests.junit.PATH_ENV_VAR is set, so
the same run that reports to the output window can be read by CI. Reporting is off
unless that variable is set, so running tests by hand leaves no files behind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verbosity
|
int
|
verbosity level. |
required |
suite_name
|
str
|
suite name for the report. Defaults to the runner's. |
None
|
Source code in pyrevitlib/pyrevit/unittests/runner.py
Attributes
writer = OutputWriter()
instance-attribute
suite_name = suite_name or junit.DEFAULT_SUITE_NAME
instance-attribute
Methods:
getDescription(test)
staticmethod
Returns the description of the test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test
|
TestCase
|
Unit test. |
required |
Returns:
| Type | Description |
|---|---|
str
|
test description |
stopTestRun()
Writes the JUnit report, when one is configured.
The whole report goes out in one file here rather than per test, so the result is
a single well-formed document. Reporting is off unless
junit.PATH_ENV_VAR is set, so running tests by hand leaves no files behind.
Source code in pyrevitlib/pyrevit/unittests/runner.py
startTest(test)
Starts the test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test
|
TestCase
|
unit test |
required |
Source code in pyrevitlib/pyrevit/unittests/runner.py
addSuccess(test)
Adds a test success.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test
|
TestCase
|
unit test case |
required |
Source code in pyrevitlib/pyrevit/unittests/runner.py
addError(test, err)
Adds a test error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test
|
TestCase
|
unit test case |
required |
err
|
OptExcInfo
|
test exception info |
required |
Source code in pyrevitlib/pyrevit/unittests/runner.py
addFailure(test, err)
Adds a test failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test
|
TestCase
|
unit test case |
required |
err
|
OptExcInfo
|
test exception info |
required |
Source code in pyrevitlib/pyrevit/unittests/runner.py
addSkip(test, reason)
Adds a skipped test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test
|
TestCase
|
unit test case |
required |
reason
|
str
|
why it was skipped |
required |
Source code in pyrevitlib/pyrevit/unittests/runner.py
PyRevitTestRunner(verbosity=1, failfast=False, use_buffer=False, resultclass=None, suite_name=None)
Bases: object
Test runner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verbosity
|
int
|
level of vermosity. Defaults to 1. |
1
|
failfast
|
bool
|
if True, stops at the first failure. Defaults to False. |
False
|
use_buffer
|
bool
|
use a buffer. Defaults to False. |
False
|
resultclass
|
type
|
Class to use to hold the results.
Defaults to |
None
|
suite_name
|
str
|
suite name recorded in the JUnit report. |
None
|
Source code in pyrevitlib/pyrevit/unittests/runner.py
Attributes
resultclass = PyRevitTestResult
class-attribute
instance-attribute
verbosity = verbosity
instance-attribute
failfast = failfast
instance-attribute
use_buffer = use_buffer
instance-attribute
suite_name = suite_name
instance-attribute
Methods:
run(test)
Runs a test suite.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test
|
TestSuite
|
Test suite to run |
required |
Returns:
| Type | Description |
|---|---|
PyRevitTestResult
|
Test suite results. |
Source code in pyrevitlib/pyrevit/unittests/runner.py
Functions:
run_module_tests(test_module)
Runs the unit tests of the given module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_module
|
module
|
module with tests |
required |
Returns:
| Type | Description |
|---|---|
PyRevitTestResult
|
tests results. |
Source code in pyrevitlib/pyrevit/unittests/runner.py
run_test_case(test_case)
Runs the unit test of the given TestCase class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_case
|
type[TestCase]
|
TestCase class with tests |
required |
Returns:
| Type | Description |
|---|---|
PyRevitTestResult
|
tests results. |
Source code in pyrevitlib/pyrevit/unittests/runner.py
assert_module_tests_successful(test_module)
Runs a module's unit tests and fails the command if any of them failed.
run_module_tests only reports; discarding its result makes a red suite
look like a green button, so command scripts must go through this instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_module
|
module
|
module with tests |
required |
Returns:
| Type | Description |
|---|---|
PyRevitTestResult
|
tests results. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
if the module has failures, errors, or unexpected successes. The traceback of each offending test is already in the output window, so the message only needs to name the module and the counts. |
Note
IronPython 2.7's TestResult.wasSuccessful ignores
unexpectedSuccesses (unittest/result.py returns
len(self.failures) == len(self.errors) == 0), so on the default engine
an @expectedFailure that starts passing does not fail the command.
CPython does count them, which is why the third count is listed.