{"id":1769,"library":"unittest-xml-reporting","title":"unittest-xml-reporting","description":"unittest-xml-reporting is a unittest-based test runner that generates XML reports in the xUnit format. These reports are widely compatible with various tools, including build systems, IDEs, and continuous integration servers like Jenkins or GitLab. The library is actively maintained with regular releases; its current major version is 4.0.0.","status":"active","version":"4.0.0","language":"en","source_language":"en","source_url":"http://github.com/xmlrunner/unittest-xml-reporting/tree/master/","tags":["testing","unittest","xml","junit","reporting","ci-cd"],"install":[{"cmd":"pip install unittest-xml-reporting","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Requires Python 3.10+ for version 4.0.0. Older versions of the library supported earlier Python versions.","package":"Python","optional":false}],"imports":[{"note":"The primary runner class is accessed via the 'xmlrunner' module.","symbol":"XMLTestRunner","correct":"import xmlrunner\n# ...\nxmlrunner.XMLTestRunner(...)"}],"quickstart":{"code":"import unittest\nimport xmlrunner\nimport os\n\nclass MyTests(unittest.TestCase):\n    def test_success(self):\n        self.assertTrue(True)\n\n    def test_failure(self):\n        self.assertEqual(1, 2, \"1 is not equal to 2\")\n\n    @unittest.skip(\"demonstrating skipping\")\n    def test_skipped(self):\n        self.fail(\"shouldn't run this\")\n\nif __name__ == '__main__':\n    output_dir = os.environ.get('TEST_OUTPUT_DIR', 'test-reports')\n    os.makedirs(output_dir, exist_ok=True)\n    \n    # Run tests and generate XML report in the specified directory\n    unittest.main(\n        testRunner=xmlrunner.XMLTestRunner(output=output_dir),\n        # Using exit=False allows the script to continue after tests,\n        # which can be useful in some CI/CD setups or when integrating.\n        exit=False\n    )\n\n    print(f\"Test reports generated in: {os.path.abspath(output_dir)}\")","lang":"python","description":"This quickstart demonstrates how to set up a basic unittest suite and run it using `xmlrunner.XMLTestRunner` to generate xUnit-compatible XML reports in a specified output directory."},"warnings":[{"fix":"Upgrade Python to 3.10+ or downgrade `unittest-xml-reporting` to a compatible version (e.g., `pip install unittest-xml-reporting==3.2.0` for Python 3.7-3.9).","message":"Version 4.0.0 of `unittest-xml-reporting` requires Python 3.10 or newer. If you are using an older Python version (e.g., 3.7-3.9), you must use an earlier version of the library (e.g., 3.2.0).","severity":"breaking","affected_versions":"<4.0.0 for Python <3.10"},{"fix":"Be aware that reports for tests using `subTest` might lack fine-grained detail. Consider restructuring complex sub-tests into individual test methods if detailed reporting is critical for each variation.","message":"The `unittest.TestCase.subTest` feature has limited support. Sub-test granularity may be lost in the generated XML reports as it does not map directly to the xUnit schema, and successful sub-tests might not be explicitly reported.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your XML files strictly adhere to the JUnit XML format. Validate reports as part of your CI pipeline, ensure correct output paths, and check for unique test names and classes.","message":"Malformed JUnit XML reports are a common issue, leading to parsing errors in CI/CD systems like GitLab or Jenkins. This can be caused by invalid XML, encoding problems, or missing test data.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Refer to the documentation of your specific Jenkins xUnit plugin version. If issues arise, consider configuring the plugin to use a more lenient XSD or adjusting the report generation to match its expected schema.","message":"When consuming reports in Jenkins, different versions of the Jenkins xUnit plugin may have varying levels of XSD validation strictness. This can cause valid reports for one plugin version to be rejected by another.","severity":"gotcha","affected_versions":"All versions depending on CI environment"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}