junit
JUnit XML reporting for the in-Revit unit test suites.
The suites in this package run inside Revit and report to the output window, which CI cannot read. This module renders the same outcomes as JUnit XML so a runner can upload them and a reader gets failures inline in the job summary.
Deliberately free of pyrevit imports so a plain CPython test can load it without a Revit host. Targets IronPython 2.7 as well as CPython 3, since 2.7 is the default engine.
Attributes
DEFAULT_SUITE_NAME = 'pyrevit.unittests'
module-attribute
PATH_ENV_VAR = 'PYREVIT_TEST_JUNIT_PATH'
module-attribute
Classes
JUnitReport(name=DEFAULT_SUITE_NAME, timestamp=None)
Bases: object
Accumulates test outcomes and renders them as a JUnit XML document.
One report describes one <testsuite>. A suite that reports more than once appends,
see write.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
|
DEFAULT_SUITE_NAME
|
timestamp
|
str
|
ISO-8601 suite stamp. Defaults to the current time. |
None
|
Source code in pyrevitlib/pyrevit/unittests/junit.py
Attributes
name
property
str: the <testsuite> name.
total
property
int: number of reported test cases.
Methods:
add_success(test_id, classname=None, duration=0.0)
Records a passing test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_id
|
str
|
test name as it should appear in a report. |
required |
classname
|
str
|
suite or class the test belongs to. |
None
|
duration
|
float
|
seconds the test took. |
0.0
|
Source code in pyrevitlib/pyrevit/unittests/junit.py
add_failure(test_id, message, trace=None, classname=None, duration=0.0)
Records a failing assertion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_id
|
str
|
test name. |
required |
message
|
str
|
short reason. |
required |
trace
|
str
|
traceback or detail. |
None
|
classname
|
str
|
suite or class the test belongs to. |
None
|
duration
|
float
|
seconds the test took. |
0.0
|
Source code in pyrevitlib/pyrevit/unittests/junit.py
add_error(test_id, message, trace=None, classname=None, duration=0.0)
Records a test that raised instead of failing an assertion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_id
|
str
|
test name. |
required |
message
|
str
|
short summary. |
required |
trace
|
str
|
traceback or detail. |
None
|
classname
|
str
|
suite or class the test belongs to. |
None
|
duration
|
float
|
seconds the test took. |
0.0
|
Source code in pyrevitlib/pyrevit/unittests/junit.py
add_skipped(test_id, reason=None, classname=None, duration=0.0)
Records a skipped test.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_id
|
str
|
test name. |
required |
reason
|
str
|
why it was skipped. |
None
|
classname
|
str
|
suite or class the test belongs to. |
None
|
duration
|
float
|
seconds the test took. |
0.0
|
Source code in pyrevitlib/pyrevit/unittests/junit.py
to_xml()
Renders the report.
Returns:
| Name | Type | Description |
|---|---|---|
str |
XML document with an XML declaration. |
Source code in pyrevitlib/pyrevit/unittests/junit.py
write(path=None)
Writes the report, replacing any previous file and creating parents as needed.
Important: writes once per run. Writing per outcome would either lose earlier results or leave several root elements in the file, which no JUnit consumer accepts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
destination file. Defaults to |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
the path written, or None when reporting is off. |
Source code in pyrevitlib/pyrevit/unittests/junit.py
Functions:
report_path()
The configured report path, or None when reporting is off.
Returns:
| Name | Type | Description |
|---|---|---|
str |
path from |