A pytest plugin for generating HTML reports of test results with enhanced visualizations and extensibility.
npx @tessl/cli install tessl/pypi-pytest-html@4.1.0A comprehensive pytest plugin that generates professional HTML reports for test results. pytest-html captures test execution data, metadata, and results, then renders them into visually appealing and interactive HTML reports with filtering capabilities, detailed test information, and support for embedded multimedia content.
pip install pytest-htmlimport pytest_htmlFor accessing extras functionality:
import pytest_html.extrasFor accessing specific extras functions:
from pytest_html import extras
from pytest_html.extras import html, image, json, text, url, video# Generate a basic HTML report
# Command line: pytest --html=report.html
# Add extra information to a test
def test_example(extras):
extras.append(pytest_html.extras.url("https://example.com"))
extras.append(pytest_html.extras.text("Additional context"))
assert True
# Generate self-contained report (embeds CSS/JS)
# Command line: pytest --html=report.html --self-contained-htmlpytest-html integrates with pytest's plugin system and hook architecture:
Core command-line options and configuration settings for controlling HTML report generation, output format, and styling options.
# Command line options
--html=PATH # Create HTML report file at given path
--self-contained-html # Create self-contained HTML with embedded assets
--css=PATH # Append CSS file content to report style (can be used multiple times)# Configuration options (pytest.ini)
[tool:pytest]
render_collapsed = "passed" # Row(s) to render collapsed on open
max_asset_filename_length = 255 # Maximum filename length for assets
initial_sort = "result" # Column to initially sort on
generate_report_on_test = false # Generate report after each test
environment_table_redact_list = # Regexes for redacting env variables
password.*
secret.*Fixtures for adding multimedia content, metadata, and additional information to individual test results within the HTML report.
@pytest.fixture
def extras(pytestconfig): ...
@pytest.fixture
def extra(pytestconfig): ... # DEPRECATED: Use extras insteadFunctions for creating rich multimedia content that can be embedded in HTML test reports, including images, videos, JSON data, and external links.
def html(content): ...
def image(content, name="Image", mime_type="image/png", extension="png"): ...
def json(content, name="JSON"): ...
def text(content, name="Text"): ...
def url(content, name="URL"): ...
def video(content, name="Video", mime_type="video/mp4", extension="mp4"): ...Pytest hooks for customizing report content, formatting, and behavior during report generation.
def pytest_html_report_title(report): ...
def pytest_html_results_summary(prefix, summary, postfix, session): ...
def pytest_html_results_table_header(cells): ...
def pytest_html_results_table_row(report, cells): ...
def pytest_html_results_table_html(report, data): ...
def pytest_html_duration_format(duration): ...# Extra content structure (dictionary returned by extra functions)
Extra = {
"name": str | None,
"format_type": str,
"content": str,
"mime_type": str | None,
"extension": str | None
}
# Format type constants
FORMAT_HTML = "html"
FORMAT_IMAGE = "image"
FORMAT_JSON = "json"
FORMAT_TEXT = "text"
FORMAT_URL = "url"
FORMAT_VIDEO = "video"
# Package metadata
__version__ = "4.1.1" # Or "unknown" if package is not built with setuptools_scm
__pypi_url__ = "https://pypi.python.org/pypi/pytest-html"