A pytest plugin for generating HTML reports of test results with enhanced visualizations and extensibility.
—
Pytest fixtures that enable tests to add rich multimedia content and metadata to HTML reports. These fixtures provide a way to include additional context, debugging information, screenshots, logs, and other relevant data alongside test results.
The primary fixture for adding extra content to test reports. Provides a list that tests can append extra content items to, which will be displayed in the HTML report.
@pytest.fixture
def extras(pytestconfig):
"""
Add details to the HTML reports.
This fixture provides a list that tests can append extra content to.
Content added via extras will be displayed in the HTML report for
the specific test.
Parameters:
- pytestconfig: pytest configuration object
Yields:
- list: List to append extra content items to
Usage:
def test_example(extras):
extras.append(pytest_html.extras.url("https://example.com"))
extras.append(pytest_html.extras.text("Debug info"))
"""Usage Example:
import pytest_html
def test_with_extras(extras):
# Add a URL for reference
extras.append(pytest_html.extras.url("https://api.example.com/status"))
# Add debugging text
extras.append(pytest_html.extras.text("Database connection: OK"))
# Add a screenshot (base64 encoded)
with open("screenshot.png", "rb") as f:
screenshot_data = base64.b64encode(f.read()).decode()
extras.append(pytest_html.extras.png(screenshot_data, "Test Screenshot"))
# Add JSON data
debug_data = {"user_id": 123, "session": "abc123"}
extras.append(pytest_html.extras.json(debug_data, "Debug Data"))
# Test logic here
assert TrueLegacy fixture that provides the same functionality as extras. This fixture is deprecated and will be removed in a future release.
@pytest.fixture
def extra(pytestconfig):
"""
DEPRECATED: Add details to the HTML reports.
This fixture is deprecated and will be removed in a future release.
Use 'extras' instead.
Parameters:
- pytestconfig: pytest configuration object
Yields:
- list: List to append extra content items to
"""The fixtures work by storing extra content in pytest's stash system using a special key. The content is then processed during report generation and embedded into the HTML output.
# Stash key for storing extras data
extras_stash_key = pytest.StashKey[list]()The fixtures store data in pytestconfig.stash[extras_stash_key] which is then accessed by the plugin during report generation via the pytest_runtest_makereport hook.
Extra content added through fixtures is processed during the pytest_runtest_makereport hook:
report.extra (with deprecation warning)report.extrasThis ensures that all extra content from various sources is properly included in the final HTML report.
Install with Tessl CLI
npx tessl i tessl/pypi-pytest-html