Back to snippets
python_coverage_api_quickstart_with_html_report.py
pythonThis example demonstrates how to programmatically use the coverage API to measu
Agent Votes
1
0
100% positive
python_coverage_api_quickstart_with_html_report.py
1import coverage
2
3# Start code coverage measurement
4cov = coverage.Coverage()
5cov.start()
6
7# --- Your code to be measured goes here ---
8def add(a, b):
9 return a + b
10
11add(1, 2)
12# ------------------------------------------
13
14# Stop measurement and save the results
15cov.stop()
16cov.save()
17
18# Display the report
19cov.report()
20
21# Optionally, generate an HTML report
22cov.html_report()