{"id":5272,"library":"junit-xml-2","title":"junit-xml-2","description":"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.","status":"maintenance","version":"1.9","language":"en","source_language":"en","source_url":"https://github.com/returntocorp/python-junit-xml","tags":["testing","junit","xml","ci","report","test-results"],"install":[{"cmd":"pip install junit-xml-2","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"TestSuite","correct":"from junit_xml import TestSuite"},{"symbol":"TestCase","correct":"from junit_xml import TestCase"}],"quickstart":{"code":"from junit_xml import TestSuite, TestCase\n\n# Create a list of test cases\ntest_cases = [\n    TestCase('TestFoo', 'some.class.name', 123.345, 'I am stdout!', 'I am stderr!'),\n    TestCase('TestBar', 'another.class', 54.123)\n]\n\n# Create a test suite and add test cases\nts = TestSuite(\"MyTestSuite\", test_cases)\n\n# Add a failing test case\nfailing_test = TestCase('TestFailure', 'failing.class', 10.0)\nfailing_test.add_failure_info('Assertion failed: expected X got Y', 'Traceback...')\nts.add_testcase(failing_test)\n\n# Add an error test case\nerror_test = TestCase('TestError', 'error.class', 7.5)\nerror_test.add_error_info('Runtime error: division by zero', 'Traceback...', 'ZeroDivisionError')\nts.add_testcase(error_test)\n\n# Generate XML string (pretty printing is on by default)\nxml_string = TestSuite.to_xml_string([ts])\nprint(xml_string)\n\n# You can also write the XML to a file\n# with open('output.xml', 'w') as f:\n#     TestSuite.to_file(f, [ts], prettyprint=True)","lang":"python","description":"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."},"warnings":[{"fix":"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.","message":"junit-xml-2 is a fork with its last release (1.9) in September 2020. The upstream `junit-xml` (kyrus/python-junit-xml) has a more recent 1.9 release from January 2023. Users needing the latest bug fixes or features from the upstream should use `junit-xml` directly if possible, or be aware `junit-xml-2` might be out of sync.","severity":"gotcha","affected_versions":"<=1.9"},{"fix":"Validate the generated XML against your specific CI/parsing tool's requirements. Review the `Common JUnit XML Format & Examples` for prevalent conventions.","message":"The JUnit XML format lacks an official, universally adhered-to specification, leading to variations in how different tools generate and interpret these files. This library implements a common schema based on observed usage and Jenkins' implementation, but full compatibility across all parsing tools is not guaranteed.","severity":"gotcha","affected_versions":"All"},{"fix":"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.","message":"The library automatically removes 'illegal or discouraged' Unicode characters from the generated XML output. This behavior, while preventing XML parsing errors, can lead to silent data loss if test output contains such characters.","severity":"gotcha","affected_versions":"All"},{"fix":"Always use `TestCase.add_failure_info()` or `TestCase.add_error_info()` methods when a test fails or encounters an error to ensure proper reporting.","message":"Merely placing error output in `<system-err>` tags within a `TestCase` might not register a test as a failure or error in the `TestSuite` summary. To ensure tests are correctly counted as failed or erroneous, explicitly use `TestCase.add_failure_info(message, output, error_type)` for failures or `TestCase.add_error_info(message, output, error_type)` for errors.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}