API Documentation¶
This part of the documentation lists the full API reference of all public classes and functions.
- class junit_reporter.TestCase(name, classname=None, stdout=None, stderr=None, assertions=None, timestamp=None, elapsed_seconds=None, status=None, category=None, filename=None, line=None, log=None, url=None, enabled=True, allow_multiple_subelements=False)¶
A class that contains information about the execution of a single test case.
- Parameters:
name (
str) – The display name of the test case.classname (
str) – The full name of the class.status (
str) – The status of the test case.category (
str) – The category of the test case.stdout (
str) – The data written tostdoutduring the test execution.stderr (
str) – The data written tostderrduring the test execution.assertions (
int) – The total number of asserts run in the test cases.timestamp (
str) – The time when the test case execution started.elapsed_seconds (
float,int) – The time, in fractional seconds, spent running the tests.filename (
str) – The full file name of the test case.line (
int) – The line number of the test case.log (
str) – The log of the test case.url (
str) – The url of the test case.enabled (
bool) – If set toFalsemark the test case as disabled.allow_multiple_subelements (
bool) – If set toTruewill allow a test cases to have multiple errors, failures or skips. Defaults toFalse.
- add_error(message=None, output=None, error_type=None)¶
Adds an error message, output, or both to the test case.
- Parameters:
message (
str) – The error message.output (
str) – The error output.error_type (
str) – The error type.
- add_failure(message=None, output=None, failure_type=None)¶
Adds a failure message, output, or both to the test case.
- Parameters:
message (
str) – The failure message.output (
str) – The failure output.failure_type (
str) – The failure type.
- add_skipped(message=None, output=None)¶
Adds a skipped message, output, or both to the test case.
- Parameters:
message (
str) – The skip message.output (
str) – The skip output.
- finish()¶
Set the elapsed seconds based on the timestamp.
- property is_enabled¶
Returns
Trueif this test case is enabled.
- property is_error¶
Returns
Trueif this test case is an error.
- property is_failure¶
Returns
Trueif this test case is a failure.
- property is_skipped¶
Returns
Trueif this test case has been skipped.
- start()¶
Set the start timestamps.
- class junit_reporter.TestSuite(name, test_cases=None, id=None, stdout=None, stderr=None, package=None, hostname=None, filename=None, log=None, url=None, timestamp=None, properties=None)¶
A class that contains information about the execution of a single test suite.
It also contains information about failures/errors related to the test cases contained by the test suite.
- Parameters:
test_cases (
list) – A list ofTestCase.id (
str) – The id of the test suite.stdout (
str) – The data written tostdoutduring the test execution.stderr (
str) – The data written tostderrduring the test execution.package (
str) – The package name of the test suite.hostname (
str) – The hostname of the test suite.filename (
str) – The full file name of the test suite.log (
str) – The log of the test suite.url (
str) – The url of the test suite.timestamp (
str) – The time when the test suite execution started.properties (
dict) – The test suite properties.
- add_test_case(test_case)¶
Add a test case to the test suite.
- class junit_reporter.JUnitReporter(test_suites=None)¶
A test reporter class that can express test results in a Junit XML report.
- Parameters:
test_suites (
list) – A list ofTestSuite.
- add_test_suite(test_suite)¶
Add a test suite to the report.
- create_test_suite(*args, **kwargs)¶
Create a new test suite and add it to the report.
Arguments and optional keyword arguments correspond to the
TestSuiteconstructor arguments, documented above.- Returns:
The new test suite.
- Return type:
- classmethod report_to_string(test_suites, prettyprint=True)¶
Generates a string representation of the JUnit XML.
- to_string(prettyprint=True)¶
Generates a string representation of the JUnit XML.
- write(filename='report.xml', prettyprint=True)¶
Writes the JUnit report to a file, as XML.
- classmethod write_report(test_suites, filename='report.xml', prettyprint=True)¶
Generate the JUnit XML and writes the XML to the specified file.