Recommended Free Tools
Save a pytest-html report at a chosen path and make it portable with pytest --html=reports/test-results.html --self-contained-html. The report directory must already exist and be writable. From there, configure its title, environment panel, redaction rules, and per-test extras in pytest hooks or pytest configuration.
Save the report to a specific path
Use --html to select the destination file. Add --self-contained-html when you want the report delivered as one HTML file:
As an Amazon Associate I earn from qualifying purchases.
pytest --html=reports/test-results.html --self-contained-html
The directory portion of the path is a normal filesystem path; ensure reports exists and the test process can write to it. The plugin documents --html=report.html as the basic form of the option. pytest-html user guide
Choose between separate assets and one self-contained file
| Output choice | What to expect | Best fit |
|---|---|---|
| Default report | Stores assets separately, following the plugin’s Content Security Policy approach. | Keeping the report and its supporting assets together in a build or CI artifact. |
--self-contained-html |
Embeds assets such as CSS and images into the HTML file. Images added as file or URL extras may still be external, so they can fail to display after moving the report. | Sharing or publishing a single report file, while checking any attached images separately. |
The standalone option improves portability, but does not guarantee that every extra image is embedded. The plugin specifically warns about file- and URL-based image extras. pytest-html user guide
#1 Best Overall
Set a custom report title
Without a title hook, pytest-html uses the report filename as its title. Add pytest_html_report_title to your project’s conftest.py to set a more descriptive label:
def pytest_html_report_title(report):
report.title = "Nightly API test results"
Add metadata to the Environment panel
The Environment panel is provided through pytest-metadata. Import its metadata_key and modify the metadata mapping in a hook. Put this in conftest.py when the value is known at configuration time:
Rank #2
from pytest_metadata.plugin import metadata_key
def pytest_configure(config):
config.stash[metadata_key]["Build"] = "nightly"
If the value is not available until tests have finished, update it in pytest_sessionfinish. Mark the hook tryfirst=True so the reporting plugins see the change before they consume the metadata:
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →import pytest
from pytest_metadata.plugin import metadata_key
@pytest.hookimpl(tryfirst=True)
def pytest_sessionfinish(session, exitstatus):
session.config.stash[metadata_key]["Build"] = "nightly"
Metadata values are alphabetized unless the metadata uses an OrderedDict. pytest-html user guide
Redact sensitive environment values
Set environment_table_redact_list in pytest configuration to regex patterns matching Environment table variable names. Matching values are grayed out; their names remain visible. For example, add this to pytest.ini:
[pytest]
environment_table_redact_list = ^API_TOKEN$
.*PASSWORD.*
Adjust the patterns to match the names your test environment actually emits. pytest-html user guide
Rank #4
Attach test-specific extras
On pytest-html 4.x, use report.extras and the extras fixture. The older report.extra attribute and extra fixture are deprecated. This hook attaches a text extra to failed test calls:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
import pytest
import pytest_html
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
extras = getattr(report, "extras", [])
if report.when == "call" and report.failed:
extras.append(pytest_html.extras.text("Inspect the captured trace"))
report.extras = extras
Documented extra types include HTML, JSON, plain text, URLs, and images. For image extras, remember that a self-contained report may still refer to an external file or URL. pytest-html user guide pytest-html deprecations
Best Value
Customize summary content, result columns, and sorting
Use plugin hooks for report content that is not controlled by the output command:
pytest_html_results_summary(prefix, summary, postfix)appends summary material.pytest_html_results_table_header(cells)andpytest_html_results_table_row(report, cells)customize table headers and rows.pytest_html_results_table_html(report, data)changes additional per-result HTML or log output.
The guide also documents initial_sort for the table’s starting sort order, URL parameters for sorting and visible outcomes, and render_collapsed for initially collapsed rows. A URL query parameter takes precedence over render_collapsed. pytest-html user guide
Account for pytest-html 4.x changes
The deprecations page dates the move from report.extra and the extra fixture to their plural forms to version 4.0.0. It also marks render_collapsed = True as deprecated in favor of values matching the query parameter, such as all, and says duration_formatter was removed and no longer has an effect. pytest-html deprecations
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchThe changelog records pytest-html 4.1.1 on 2023-11-07 and describes 4.0.0 as a major rewrite. That dated entry does not establish which release is latest now; check the project’s release information when selecting a version. pytest-html changelog
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




