or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

extras.mdfixtures.mdhooks.mdindex.md
tile.json

tessl/pypi-pytest-html

A pytest plugin for generating HTML reports of test results with enhanced visualizations and extensibility.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pytest-html@4.1.x

To install, run

npx @tessl/cli install tessl/pypi-pytest-html@4.1.0

index.mddocs/

pytest-html

A 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.

Package Information

  • Package Name: pytest-html
  • Language: Python
  • Installation: pip install pytest-html

Core Imports

import pytest_html

For accessing extras functionality:

import pytest_html.extras

For accessing specific extras functions:

from pytest_html import extras
from pytest_html.extras import html, image, json, text, url, video

Basic Usage

# 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-html

Architecture

pytest-html integrates with pytest's plugin system and hook architecture:

  • Plugin Entry Points: Registered as pytest11 plugins for automatic discovery
  • Report Generation: Uses Jinja2 templating for flexible HTML generation
  • Asset Management: Supports both linked assets and self-contained reports
  • Extensibility: Provides hooks for customizing report content and formatting
  • Test Integration: Uses pytest fixtures to collect additional test metadata

Capabilities

Command Line Interface

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.*

Test Fixtures

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 instead

Test Fixtures

Content Extras

Functions 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"): ...

Content Extras

Report Customization Hooks

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): ...

Report Customization Hooks

Types

# 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"