junit-xml-2 (version 1.9) is a Python library designed for creating JUnit XML test result documents. It is a fork of `https://github.com/kyrus/python-junit-xml`, primarily created to ensure a tarball was published to PyPI. The library currently appears to be in maintenance mode, with its last release in September 2020, while the original project it forked from has seen more recent updates.
pip install junit-xml-2Verified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create `TestCase` and `TestSuite` objects, add details like stdout/stderr, and correctly register test failures and errors. The generated XML can then be printed to the console or written to a file. This code is based on the usage pattern of the `junit-xml` library, which `junit-xml-2` is a fork of.
Consider `pip install junit-xml` for the actively maintained version if newer features or fixes are required, or consult the `junit-xml-2` GitHub repository for specific fork changes.
Validate the generated XML against your specific CI/parsing tool's requirements. Review the `Common JUnit XML Format & Examples` for prevalent conventions.
Sanitize test output for non-standard Unicode characters before passing it to `TestCase` if preserving exact character fidelity is critical, or be aware of this automatic stripping.
Always use `TestCase.add_failure_info()` or `TestCase.add_error_info()` methods when a test fails or encounters an error to ensure proper reporting.
Ensure `junit-xml-2` is installed via `pip install junit-xml-2` (or `pip install junit-xml` if you intend to use the upstream project), and then correctly import using `from junit_xml import TestSuite, TestCase`.
To correctly report failures or errors, use the `TestCase.add_failure_info(message, output, error_type)` or `TestCase.add_error_info(message, output, error_type)` methods on the `TestCase` object.
Manually sanitize or encode test output for non-standard Unicode characters before passing it to `TestCase` elements. Alternatively, ensure the environment generating the test output uses an encoding compatible with XML 1.0 specifications.
No dependency data recorded yet.