Install pytest-html in the Python environment that runs your tests, write the report to a predictable path, then configure your CI provider to upload or collect that file. A self-contained report is convenient to download and share:
pytest --html=reports/pytest.html --self-contained-html
Generating the HTML does not publish it as a build artifact by itself. Your pipeline must explicitly collect the report, including after test failures if you need reports from failed runs.
As an Amazon Associate I earn from qualifying purchases.
Generate the report with pytest-html
pytest-html is a pytest plugin that generates an HTML report of test results. Install it in the same Python environment used to invoke pytest; adding it to the project’s normal or development dependencies helps keep local and CI environments consistent.
Choose a stable output path and use that same path in your CI artifact configuration. The plugin’s user guide documents this command for a self-contained report:
#1 Best Overall
pytest --html=reports/pytest.html --self-contained-html
Create the reports directory before running pytest if it does not already exist. Without --self-contained-html, report assets such as CSS and images are stored separately by default, so collect the report together with those assets.
Upload the report as a CI artifact
Artifact configuration is specific to the CI provider. The examples below use GitHub Actions and GitLab CI; in either case, the path must match the report’s output path.
Rank #2
GitHub Actions
Use the official actions/upload-artifact action and set its path input to the report file or its containing directory. For example, the relevant steps can be structured like this:
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minute- name: Run tests and generate HTML report
run: pytest --html=reports/pytest.html --self-contained-html
- name: Upload pytest HTML report
if: always()
uses: actions/upload-artifact
with:
name: pytest-html-report
path: reports/pytest.html
The if: always() condition makes the upload step eligible to run even when the test step fails. Check the behavior in your workflow, especially if other job-level conditions or cancellation affect execution. Artifact access and retention depend on repository and workflow settings; do not assume a report is public or retained indefinitely.
Rank #3
GitLab CI
GitLab collects files declared under a job’s artifacts:paths. For example:
test:
script:
- mkdir -p reports
- pytest --html=reports/pytest.html --self-contained-html
artifacts:
when: always
paths:
- reports/pytest.html
In GitLab, when: always requests artifact collection regardless of job success or failure. Confirm how the job ends in your pipeline and consult the official job artifacts documentation for access and retention behavior, which depends on configuration.
Rank #4
Make sure the downloaded report is usable
A self-contained report embeds the ordinary report assets, which makes a single HTML file easier to download and share. It does not necessarily embed every file referenced by added report extras. The plugin warns when files or links are added to a self-contained report; screenshots and other linked resources may still need to be uploaded alongside the HTML file. If you use those extras, collect the referenced files or the whole directory and preserve their relative paths.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →- Run the workflow and open the artifact in the CI interface.
- Download it and open
pytest.htmllocally. - Check that the report renders and that any screenshots, linked files, or other extras you rely on are available.
Collect reports from failed test runs
Test commands commonly return a failure status when tests fail, and some CI configurations stop or skip later steps after that status. If you need a report for failed runs, configure artifact collection to run despite test failure using the provider’s appropriate syntax, then verify the failed-test path in your own pipeline. The GitHub Actions and GitLab examples above show provider-specific approaches; do not assume a successful upload merely because the report file was generated.
Best Value
Keep HTML and test-result integrations distinct
The workflow here produces an HTML report through pytest-html. JUnit XML is a different output format and may be used by CI integrations that consume XML results; it is not a substitute for uploading the HTML file when readers need the pytest-html report. If your pipeline needs both, configure each output and artifact or integration separately.
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.




