pytest-html is a plugin for the pytest testing framework that generates comprehensive HTML reports for test results. It provides a visual overview of test runs, including pass/fail status, durations, and detailed information for each test. The library is actively maintained, with version 4.2.0 being the current release, and follows a frequent release cadence, addressing bug fixes and improvements regularly.
pip install pytest-htmlVerified import paths — ran on the pinned version, not inferred.
Create a test file (e.g., `test_example.py`). Run pytest from your terminal, specifying the `--html` option to define the report filename and `--self-contained-html` to embed all CSS/JS directly into the HTML, making it easier to share.
Upgrade Python to 3.8 or newer, or downgrade pytest-html to a 3.x.x version.
Remove explicit dependencies on `py` if no longer needed. The `py.xml.html` module is still implicitly available via `pytest-html`'s internal usage or if `pytest` itself provides it, but consider direct HTML string generation for custom content where possible to reduce implicit dependencies.
Remove `duration_formatter` as it's no longer supported. Update `render_collapsed = True` in your `pytest.ini` or `pyproject.toml` to `render_collapsed = all`.
Update your `conftest.py` hooks or test functions to use `report.extras.append(...)` and inject content via the `extras` fixture instead of `extra`.
For truly self-contained reports with images, embed images directly into the HTML using base64 encoding if possible, or ensure external image files are bundled and accessible alongside the report.
This is a known issue (GitHub #849). Check the project's issue tracker for updates. Downgrading to v3.2.0 might temporarily resolve it, or refactor custom column additions to a different hook or mechanism if available.