pysysjava.junitxml

Support for reading the Ant-style XML files often used for report JUnit results (and also for some non-JUnit test execution engines).

JUnitXMLParser

class pysysjava.junitxml.JUnitXMLParser(path)[source]

Bases: object

A fast, minimal parser for Ant-style JUnit XML files.

Note that there are a number of dialects of this file format with different handling of things like stdout (per testsuite or per testcase) and timezone (UTC or local timezone) so check the details carefully if using this for anything other than the JUnit 5 console launcher. If you need something more advanced there are other Python-based JUnit XML parsers out there with more features.

outcomeDetailsExcludeLinesRegex = '^\\t+(at (java[.]|sun[.]|org[.]junit|org.apache.tools.ant)|\\.\\.\\. [0-9]+ more).*\\n'

A regular expression specifying lines that should be stripped out of the outcomeDetails stack traces.

isTimestampLocalTime = None

Set to True to force timestamp to be interpreted as local time (like JUnit5), or False to force to interpret as UTC/GMT (like Ant). Default is to select based on test suite name.

parse()[source]

Parses this file and returns a tuple of (testsuite: dict[str,obj], testcases: list[dict[str,obj]]) representing the contents of this file.

The testsuite dictionary contains keys:

  • tests: int - total number of tests executed (depending on the dialect of the file format this may or may not include skipped tests).

  • durationSecs: float - The time elapsed while executing all tests.

  • timestamp: float - The start time as a POSIX timestamp which can be passed to datetime.fromtimestamp().

  • stdout: str (optional) - Any text written to stdout by all testcases in the suite for dialects such as Ant which don’t provide this per-testcase. (stripped of leading/trailing whitespace)

  • stderr: str (optional) - Any text written to stderr by all testcases in the suite for dialects such as Ant which don’t provide this per-testcase. (stripped of leading/trailing whitespace)

  • other keys vary depending on the dialect

Each testcase dictionary contains keys:

  • classname: str - The qualified class name containing this testcase. May include $ if has a nested class.

  • name: str - The name of the testcase, typically a method name possibly with a suffix e.g. foo()[2].

  • durationSecs: float - The time taken to execute this testcase.

  • stdout: str (optional) - Any text written to stdout by the testcase (stripped of leading/trailing whitespace), for dialects such as JUnit5 console launcher that provide this per testcase.

  • stderr: str (optional) - Any text written to stderr by the testcase (stripped of leading/trailing whitespace), for dialects such as JUnit5 console launcher that provide this per testcase

  • outcome: str - passed/failure/error/skipped.

  • outcomeType: str (optional) - Java class of the outcome type, if present.

  • outcomeReason: str (except if test passed) - reason string or ‘’ if not known.

  • outcomeDetails: str (optional) - multi-line details string for the outcome, typically a stack trace. To avoid excessive verbosity lines involving org.junit.* or java.* packages are excluded.

  • outcomeDetailsFull: str (optional) - multi-line details string for the outcome, without exclusions.

  • comparisonExpected/comparisonActual: str (optional) - actual and expected comparison values from the outcomeReason, if known.