Pytest HTML1 Reporter
Pytest-reporter-html1 is a basic HTML report template for Pytest, leveraging the Jinja2 template engine. It extends `pytest-reporter` to generate rich, expandable reports covering test files, phases, and detailed test information. The current version is 0.9.5, and it maintains an active release cadence for bug fixes and feature enhancements.
Common errors
-
pytest: error: unrecognized arguments: --html=report.html
cause Attempting to use the `--html` argument, which is associated with `pytest-html`, instead of the correct `--report` argument for `pytest-reporter-html1`.fixChange the command-line argument from `--html=report.html` to `--report=report.html` and ensure you also specify `--template=html1/index.html`. Example: `pytest --template=html1/index.html --report=report.html`. -
TypeError: unhashable type: 'dict' during report generation
cause This error has been reported in GitHub issues and can occur with specific test structures or interactions with other plugins, where dictionary objects are incorrectly used as hashable keys.fixCheck for open issues on the `pytest-reporter-html1` GitHub repository, ensure all related plugins (e.g., `pytest`, `pytest-reporter`) are up-to-date, and consider simplifying complex test data structures if a minimal reproducible example can be created. If the issue persists, filing a bug report with a minimal reproducible example is recommended.
Warnings
- gotcha Confusing `--html` with `--report`: Users migrating from or familiar with `pytest-html` often incorrectly try to use `--html=report.html` for report generation. `pytest-reporter-html1` uses `--report=report.html` instead.
- gotcha No native screenshot support: Unlike some other HTML reporters, `pytest-reporter-html1` does not natively support embedding screenshots on test failures. Custom `pytest` hooks (e.g., `pytest_runtest_makereport`) must be implemented to add this functionality.
- deprecated `DeprecationWarning: 'jinja2.Markup'` for older versions: Versions of `pytest-reporter-html1` prior to 0.8.x might issue a `DeprecationWarning` related to `jinja2.Markup`, advising to import `markupsafe.Markup` instead.
Install
-
pip install pytest-reporter-html1
Quickstart
# tests/test_example.py
def test_success():
assert True
def test_failure():
assert False
# Run from your terminal in the project root
# This command will generate a detailed HTML report named 'report.html'
# using the html1 template.
# pytest --template=html1/index.html --report=report.html
# To make the report self-contained (embed CSS, JS, images):
# pytest --template=html1/index.html --report=report.html --split-report=False
# Note: --split-report=False is the default behavior. For older versions, --self-contained might be used, but is deprecated.
# To split assets (CSS, JS, images) into separate files:
# pytest --template=html1/index.html --report=report.html --split-report