Meaning
Generates an HTML coverage report in the specified directory.
Primary Function
Generate an HTML coverage report from coverage data.
Communicative Purpose
Instruct the coverage tool to produce an HTML report for visual inspection of test coverage.
Pattern
cov.html_report(directory='<path>')
Core Structure
cov.html_report(directory='<path>')
Função primária
Generate an HTML coverage report from coverage data.
Propósito comunicativo
Instruct the coverage tool to produce an HTML report for visual inspection of test coverage.
Situações de gatilho
After running tests with coverage enabled, when a developer wants to inspect which lines of code were executed.
Contextos
Within a Python test suite that uses coverage.py, after calling cov.start() before tests and cov.stop() after tests.
Padrão
cov.html_report(directory='<path>')
Estrutura central
cov.html_report(directory='<path>')
Slots de substituição
directory: str (path to output directory, default 'htmlcov')
Colocados típicos
- cov.start()
- cov.stop()
- cov.save()
- cov.report()
Substituições comuns
- directory='cov_html'
- directory='./coverage'
- directory='htmlcov' (default)
- directory='./htmlcov'
Erros comuns
Forgetting to call cov.start() before tests leading to empty report; forgetting cov.stop() or cov.save() before generating report, resulting in incomplete data; specifying a non‑existent or inaccessible directory causing IOError; using relative paths that resolve incorrectly relative to the current working directory.
Similar / contraste
cov.report() – generates a terminal‑based coverage report; cov.xml_report() – produces an XML report for CI integration; cov.html_report(directory='cov', show_contexts=True) – includes contextual source lines in the HTML output.
Interferências
Coming from Java's JaCoCo: may expect an XML report by default; remember to call html_report() for HTML output in Python's coverage.py.
Família do chunk
- coverage reporting methods
Nuance
The directory is created if it does not exist; the report includes source code with green/red highlighting; generation is fast after test execution but can be disk‑intensive for large projects; the report can be opened in any browser without a server.
Efeito pragmático
Enables quick visual identification of untested lines, helping improve test coverage and code quality.
Dica de memória
Think of html_report as developing a photograph of your test coverage – you expose the code with tests, then develop the picture into a viewable web page.
Nota
If the directory argument is omitted, coverage.py defaults to 'htmlcov'.
Upgrade path
Consider using cov.html_report(directory='cov', show_contexts=True) for richer context, or switch to cov.xml_report() for XML reports suited to CI pipelines.
Log in to save chunks.