{"id":3526,"library":"junit2html","title":"JUnit to HTML Report Generator","description":"junit2html is a lightweight, self-contained Python tool designed to convert JUnit XML test reports into human-readable, single HTML dashboards. It's an essential utility for visualizing test results, especially within CI/CD pipelines, by transforming complex XML data into a clean and responsive HTML file. The current version is 31.0.5, indicating active development with regular updates.","status":"active","version":"31.0.5","language":"en","source_language":"en","source_url":"https://github.com/inorton/junit2html","tags":["testing","junit","html-report","ci/cd","xml-parser","test-automation"],"install":[{"cmd":"pip install junit2html","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Used for templating the HTML reports.","package":"jinja2","optional":false}],"imports":[{"note":"The primary interaction is via the command-line interface. For programmatic use, specific sub-modules like `parser` or `render` can be imported, or the `main` entry point for CLI-like behavior.","wrong":"import junit2html # no direct module-level import for CLI functionality","symbol":"CLI tool","correct":"from junit2htmlreport import main # for programmatic access to CLI internals (less common)"}],"quickstart":{"code":"# Create a dummy JUnit XML file for demonstration\n# In a real scenario, this would be generated by your test runner (e.g., pytest --junitxml=results.xml)\nimport os\n\ndummy_xml_content = '''\n<testsuites>\n  <testsuite name=\"MyTestSuite\" tests=\"2\" failures=\"1\" errors=\"0\" skipped=\"0\" time=\"0.123\">\n    <testcase classname=\"test_module.TestClass\" name=\"test_passing_case\" time=\"0.050\"/>\n    <testcase classname=\"test_module.TestClass\" name=\"test_failing_case\" time=\"0.073\">\n      <failure message=\"AssertionError: 1 != 2\">Traceback (most recent call last):...</failure>\n    </testcase>\n  </testsuite>\n</testsuites>\n'''\n\nwith open('results.xml', 'w') as f:\n    f.write(dummy_xml_content)\n\n# Run junit2html from the command line\n# This is the primary usage pattern.\n# The 'junit2html' command should be available in your PATH after installation.\n# Alternatively, use 'python -m junit2htmlreport results.xml report.html'\nimport subprocess\n\ntry:\n    # Using the installed CLI command\n    subprocess.run(['junit2html', 'results.xml', 'report.html'], check=True)\n    print(\"HTML report 'report.html' generated successfully.\")\nexcept FileNotFoundError:\n    print(\"'junit2html' command not found. Trying 'python -m junit2htmlreport'.\")\n    try:\n        # Fallback to module execution\n        subprocess.run(['python', '-m', 'junit2htmlreport', 'results.xml', 'report.html'], check=True)\n        print(\"HTML report 'report.html' generated successfully via module execution.\")\n    except subprocess.CalledProcessError as e:\n        print(f\"Error generating report: {e}\")\nexcept subprocess.CalledProcessError as e:\n    print(f\"Error generating report: {e}\")\n\n# Clean up dummy XML (optional)\nos.remove('results.xml')\n","lang":"python","description":"The primary way to use junit2html is through its command-line interface. This quickstart demonstrates how to create a dummy JUnit XML file and then convert it into an HTML report using the `junit2html` command or its module-based execution."},"warnings":[{"fix":"Use `python -m junit2htmlreport` instead of `junit2html` or ensure your Python scripts directory is in your system PATH.","message":"After `pip install junit2html`, the `junit2html` command might not be directly available in your system's PATH. If you encounter a 'command not found' error, try executing it as a Python module: `python -m junit2htmlreport JUNIT_XML_FILE [NEW_HTML_FILE]`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your JUnit XML input conforms to the standard JUnit XML schema. Validate XML structure if parsing issues occur. Pre-process non-standard XML if necessary before feeding it to junit2html.","message":"junit2html expects valid JUnit XML format. Input files with non-standard structures, incorrect encodings, or malformed XML (e.g., some outputs from Robot Framework without proper pre-processing) might lead to 'Could not find test suites in results xml' or other parsing errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to the latest stable version (e.g., `pip install --upgrade junit2html`) to get critical bug fixes and improvements.","message":"Version 31.0.4 was yanked from PyPI due to a reported bug. Users who installed this specific version might experience issues. It is recommended to update to 31.0.5 or later.","severity":"breaking","affected_versions":"31.0.4"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}