{"id":1521,"library":"junit-xml","title":"JUnit XML Generator","description":"junit-xml is a Python library for creating JUnit XML test result documents. These documents are widely used by continuous integration tools like Jenkins, GitLab CI, and others to display test outcomes. The current version is 1.9, and releases are made on an as-needed basis to add features or fix bugs.","status":"active","version":"1.9","language":"en","source_language":"en","source_url":"https://github.com/kyrus/python-junit-xml","tags":["testing","junit","xml","ci","cd","jenkins","gitlab"],"install":[{"cmd":"pip install junit-xml","lang":"bash","label":"Install latest 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\nimport os\n\n# Create some test cases\ntest_cases = [\n    TestCase('Test case 1', 'com.example.package', 1.23, stdout='Output for TC1', stderr='Error for TC1'),\n    TestCase('Test case 2', 'com.example.package', 0.5,\n             stdout='Another output', stderr='Another error')\n]\n\n# A failed test case example\nfailed_test_case = TestCase('Failed test', 'com.example.package', 0.1)\nfailed_test_case.add_failure_info('Assertion failed', 'Expected 1, got 0')\ntest_cases.append(failed_test_case)\n\n# Create a test suite and add test cases\n# The timestamp should be in ISO 8601 format\ntest_suite = TestSuite(\n    \"My example test suite\",\n    test_cases,\n    hostname=\"localhost\",\n    id=\"0\",\n    package=\"com.example.package\",\n    timestamp=\"2024-07-08T10:30:00\"\n)\n\n# Write the test suite to an XML file\noutput_filename = os.environ.get('JUNIT_XML_OUTPUT_FILE', 'output.xml')\nwith open(output_filename, 'w', encoding='utf-8') as f:\n    TestSuite.to_file(f, [test_suite], prettyprint=True)\n\nprint(f\"JUnit XML written to {output_filename}\")","lang":"python","description":"This quickstart demonstrates how to create `TestCase` objects, add them to a `TestSuite`, and then write the complete JUnit XML structure to a file. It includes examples of successful and failed tests, and uses `stdout` and `stderr` for additional messaging."},"warnings":[{"fix":"Review the new `TestCase` constructor signature and attribute names (`stdout`, `stderr`) in the documentation when upgrading from versions prior to 1.0.0.","message":"The constructor signature for `TestCase` changed significantly in version 1.0.0. Arguments like `output` and `error` were removed and replaced with `stdout` and `stderr` attributes, and the order of arguments was altered.","severity":"breaking","affected_versions":"<1.0.0 to >=1.0.0"},{"fix":"When upgrading from versions prior to 1.0.0, ensure your `TestSuite` instantiation matches the new signature, particularly the position of the `test_cases` list.","message":"The constructor signature for `TestSuite` was also updated in version 1.0.0. The `testcases` argument became a required positional argument after the suite name, and other keyword arguments were added or modified.","severity":"breaking","affected_versions":"<1.0.0 to >=1.0.0"},{"fix":"Use `datetime.now().isoformat()` or similar to generate a correctly formatted timestamp string.","message":"The `timestamp` argument for `TestSuite` expects an ISO 8601 formatted string (e.g., 'YYYY-MM-DDTHH:MM:SS'). Providing other formats may lead to invalid XML or parsing issues in consuming tools.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}