0
0
PyTesttesting~5 mins

pytest-html for HTML reports

Choose your learning style9 modes available
Introduction

pytest-html helps you create easy-to-read HTML reports after running tests. This makes it simple to see which tests passed or failed in a clear webpage format.

When you want to share test results with your team in a simple webpage.
When you need a visual report to understand test failures quickly.
When running automated tests and want to save results for later review.
When you want to keep a history of test runs with detailed reports.
When you prefer a report with colors and sections instead of plain text.
Syntax
PyTest
pytest --html=report.html

This command runs your tests and creates an HTML report named report.html.

You can open the report in any web browser to see the test results.

Examples
Run all tests and save the report as report.html in the current folder.
PyTest
pytest --html=report.html
Run tests inside the tests/ folder and save the report in the reports/ folder.
PyTest
pytest tests/ --html=reports/my_report.html
Create a single HTML file with all styles inside, so you can share it easily without extra files.
PyTest
pytest --html=report.html --self-contained-html
Sample Program

This simple test file has two tests. Running pytest with --html=report.html creates an HTML report showing both tests passed.

PyTest
def test_addition():
    assert 2 + 3 == 5

def test_subtraction():
    assert 5 - 2 == 3

# Run this in terminal:
# pytest --html=report.html
OutputSuccess
Important Notes

Make sure to install pytest-html first using pip install pytest-html.

You can customize the report with extra options like adding environment info or screenshots.

Open the generated HTML file in a browser to view the report visually.

Summary

pytest-html creates easy-to-read HTML reports for your test runs.

Use pytest --html=filename.html to generate the report.

Reports help share and understand test results quickly.