Labs ICT
โญ Pro Login

HTML Reports & Coverage

Generating professional test reports and measuring coverage.

1 min read | pytest
โญ

Want the full learning experience?

Get structured courses, certificates, projects, and instructor support with LabsICT Pro.

Explore Pro Courses

HTML Reports

pytest can generate professional HTML reports to share test results with your team.

Installing pytest-html

pip install pytest-html

Generating Reports

# Generate an HTML report
pytest --html=report.html

# Generate a self-contained report (no external CSS/JS)
pytest --html=report.html --self-contained-html

The report includes test results, durations, failure details, and filtering options.

Code Coverage

Measure how much of your code is exercised by tests using pytest-cov:

# Install
pip install pytest-cov

# Run with coverage
pytest --cov=my_package --cov-report=term-missing

# Generate HTML coverage report
pytest --cov=my_package --cov-report=html

The --cov-report=term-missing option shows which lines are not covered.

Configuring Coverage

Add coverage settings to pytest.ini or pyproject.toml:

[pytest]
addopts = --cov=my_package --cov-report=term-missing
cov-config = .coveragerc
# .coveragerc
[run]
source = my_package
omit = tests/*

[report]
fail_under = 80
show_missing = true

Combining Reports

You can generate both HTML and terminal output simultaneously:

pytest --cov=my_package \
       --cov-report=term-missing \
       --cov-report=html:htmlcov \
       --html=report.html \
       --self-contained-html

๐Ÿงช Quick Quiz

Which plugin measures test coverage?