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 to stdout during the test execution.

  • stderr (str) – The data written to stderr during 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 to False mark the test case as disabled.

  • allow_multiple_subelements (bool) – If set to True will allow a test cases to have multiple errors, failures or skips. Defaults to False.

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 True if this test case is enabled.

property is_error

Returns True if this test case is an error.

property is_failure

Returns True if this test case is a failure.

property is_skipped

Returns True if 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 of TestCase.

  • id (str) – The id of the test suite.

  • stdout (str) – The data written to stdout during the test execution.

  • stderr (str) – The data written to stderr during 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.

create_test_case(*args, **kwargs)

Create a new test cases and add it to the test suite.

Arguments and optional keyword arguments correspond to the TestCase constructor arguments, documented above.

Returns:

The new test case.

Return type:

TestCase

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 of TestSuite.

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 TestSuite constructor arguments, documented above.

Returns:

The new test suite.

Return type:

TestSuite

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.