_pytest.junitxml module

Based on initial code from Ross Lawley.

Output conforms to https://github.com/jenkinsci/xunit-plugin/blob/master/ src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd

class Junit[source]

Bases: py._xmlgen.Namespace

bin_xml_escape(arg)[source]
merge_family(left, right)[source]
class _NodeReporter(nodeid, xml)[source]

Bases: object

append(node)[source]
add_property(name, value)[source]
add_attribute(name, value)[source]
make_properties_node()[source]

Return a Junit node containing custom properties, if any.

record_testreport(testreport)[source]
to_xml()[source]
_add_simple(kind, message, data=None)[source]
write_captured_output(report)[source]
_prepare_content(content, header)[source]
_write_content(report, content, jheader)[source]
append_pass(report)[source]
append_failure(report)[source]
append_collect_error(report)[source]
append_collect_skipped(report)[source]
append_error(report)[source]
append_skipped(report)[source]
finalize()[source]
_warn_incompatibility_with_xunit2(request, fixture_name)[source]

Emits a PytestWarning about the given fixture being incompatible with newer xunit revisions

record_property(request)[source]

Add an extra properties the calling test. User properties become part of the test report and are available to the configured reporters, like JUnit XML. The fixture is callable with (name, value), with value being automatically xml-encoded.

Example:

def test_function(record_property):
    record_property("example_key", 1)
record_xml_attribute(request)[source]

Add extra xml attributes to the tag for the calling test. The fixture is callable with (name, value), with value being automatically xml-encoded

_check_record_param_type(param, v)[source]

Used by record_testsuite_property to check that the given parameter name is of the proper type

record_testsuite_property(request)[source]

Records a new <property> tag as child of the root <testsuite>. This is suitable to writing global information regarding the entire test suite, and is compatible with xunit2 JUnit family.

This is a session-scoped fixture which is called with (name, value). Example:

def test_foo(record_testsuite_property):
    record_testsuite_property("ARCH", "PPC")
    record_testsuite_property("STORAGE_TYPE", "CEPH")

name must be a string, value will be converted to a string and properly xml-escaped.

pytest_addoption(parser)[source]
pytest_configure(config)[source]
pytest_unconfigure(config)[source]
mangle_test_address(address)[source]
class LogXML(logfile, prefix, suite_name='pytest', logging='no', report_duration='total', family='xunit1', log_passing_tests=True)[source]

Bases: object

finalize(report)[source]
node_reporter(report)[source]
add_stats(key)[source]
_opentestcase(report)[source]
pytest_runtest_logreport(report)[source]

handle a setup/call/teardown report, generating the appropriate xml tags as necessary.

note: due to plugins like xdist, this hook may be called in interlaced order with reports from other nodes. for example:

usual call order:

-> setup node1 -> call node1 -> teardown node1 -> setup node2 -> call node2 -> teardown node2

possible call order in xdist:

-> setup node1 -> call node1 -> setup node2 -> call node2 -> teardown node2 -> teardown node1

update_testcase_duration(report)[source]

accumulates total duration for nodeid from given report and updates the Junit.testcase with the new total if already created.

pytest_collectreport(report)[source]
pytest_internalerror(excrepr)[source]
pytest_sessionstart()[source]
pytest_sessionfinish()[source]
pytest_terminal_summary(terminalreporter)[source]
add_global_property(name, value)[source]
_get_global_properties_node()[source]

Return a Junit node containing custom properties, if any.