Pytest HTML Report Merger
pytest-html-merger is a utility designed to combine multiple HTML reports generated by the pytest-html plugin into a single, unified HTML report. It is currently at version 0.1.0 and is maintained with an active development cadence, with its latest release in July 2024.
Common errors
-
command 'pytest_html_merger' not found
cause The `pytest-html-merger` package is either not installed, or the environment where it was installed is not active/in your system's PATH.fixRun `pip install pytest-html-merger` to install the package. Ensure your virtual environment is activated if you are using one. -
ValueError: No HTML files provided. Use -i or pass individual files.
cause The `pytest_html_merger` command was executed without specifying any input HTML files via positional arguments or input directories using the `-i` flag.fixProvide the path to individual HTML report files (e.g., `pytest_html_merger report1.html report2.html -o merged.html`) or specify an input directory (e.g., `pytest_html_merger -i ./reports -o merged.html`). -
The merged HTML report appears unstyled or with missing elements.
cause This often occurs if the input HTML reports were generated without embedding their CSS, and the merger expects self-contained reports.fixRegenerate your individual pytest HTML reports using the `--self-contained-html` flag with `pytest-html` (e.g., `pytest --html=report.html --self-contained-html`).
Warnings
- gotcha The utility primarily operates as a command-line tool and does not expose a public Python API for direct programmatic integration into other Python scripts. Users expecting a Python module to import and call functions will find this to be a limitation.
- gotcha The merger assumes that the input pytest HTML reports have their CSS embedded (self-contained). If reports are generated with external CSS files, the merged report may appear unstyled or broken, as the external references might not be correctly resolved.
- gotcha The tool's functionality is dependent on the internal structure of reports generated by `pytest-html`. Future breaking changes in `pytest-html`'s report format could potentially impact the `pytest-html-merger`'s ability to combine reports correctly.
Install
-
pip install pytest-html-merger
Quickstart
# 1. Generate individual HTML reports with pytest-html # Assuming you have tests in 'my_tests' directory pytest my_tests/test_a.py --html=report_a.html pytest my_tests/test_b.py --html=report_b.html # 2. Merge the reports using pytest-html-merger pytest_html_merger report_a.html report_b.html -o merged_report.html --title "My Combined Test Results" # Or merge all HTML files in a directory # Assuming reports are in a 'reports' directory # mkdir reports && mv report_a.html report_b.html reports/ # pytest_html_merger -i reports -o merged_reports_from_dir.html