Meaning
Generates an XML coverage report file from collected coverage data.
Primary Function
Produce an XML file containing detailed code coverage metrics (lines, branches, hits, misses) for use in continuous integration pipelines or external reporting tools.
Communicative Purpose
Communicate measured code coverage to external systems or stakeholders in a standardized Cobertura‑compatible XML format.
Pattern
cov.xml_report(outfile='<filepath>')
Core Structure
cov.xml_report(outfile=<filepath>) where cov is a coverage.Coverage instance.
Função primária
Produce an XML file containing detailed code coverage metrics (lines, branches, hits, misses) for use in continuous integration pipelines or external reporting tools.
Propósito comunicativo
Communicate measured code coverage to external systems or stakeholders in a standardized Cobertura‑compatible XML format.
Situações de gatilho
After test execution when coverage data has been collected and saved, before uploading results to a CI service or archiving.
Contextos
Post‑test phase, after calling coverage.stop() and coverage.save(), as part of a CI/CD pipeline step that generates coverage artifacts.
Padrão
cov.xml_report(outfile='<filepath>')
Estrutura central
cov.xml_report(outfile=<filepath>) where cov is a coverage.Coverage instance.
Slots de substituição
cov: coverage.Coverage instance; outfile: str path to the output XML file.
Colocados típicos
- coverage run
- coverage stop
- coverage save
- coverage xml
- coverage xml report
- CI integration
- coverage report
Substituições comuns
- outfile='coverage.xml' can be replaced with any valid file path
- e.g.
- 'reports/coverage.xml' or '/tmp/coverage.xml'.
Erros comuns
- Calling xml_report before stopping and saving coverage data (misconception: data is ready immediately) → results in empty or incomplete coverage report.\n- Supplying an invalid or non‑writable file path (syntax error: wrong argument type) → raises IOError and aborts report generation.\n- Confusing xml_report with html_report or json_report (misconception: all reports share the same arguments) → produces XML when a different format was expected, breaking downstream tools.\n- Forgetting to call cov.save() before xml_report (misconception: data is auto‑saved) → the report reflects stale or missing coverage data.\n- Using an incorrect keyword argument name such as output_file instead of outfile (syntax error) → TypeError: unexpected keyword argument.
Similar / contraste
- coverage.html_report: generates a human‑readable HTML report instead of XML.\n- coverage.json_report: outputs machine‑readable JSON format for programmatic consumption.\n- coverage.report: prints a concise summary to the terminal, producing no file.
Interferências
- Coming from JUnit XML reporting: may expect the coverage XML to follow the JUnit test result schema → coverage.xml_report produces Cobertura‑style XML, so adjust downstream parsers accordingly.\n- Coming from Go’s test coverage tool: may anticipate a simple text coverage file → coverage.xml_report creates structured XML requiring an XML parser.\n- Coming from Java’s JaCoCo: may assume branch data is always present → branch information appears only if branch coverage was enabled during measurement.
Família do chunk
- coverage reporting
- coverage.xml_report
- coverage.html_report
- coverage.json_report
- coverage.report
Nuance
Do not use xml_report when a human‑readable HTML report is preferable; it adds negligible runtime overhead but requires coverage data to be saved first; note that branch data is included only if branch coverage was enabled during the measurement session.
Efeito pragmático
Enables CI systems to enforce coverage thresholds, publish coverage trends, and make gaps in test visibility actionable for developers and stakeholders.
Dica de memória
Think of cov.xml_report as taking a snapshot of your test coverage and saving it as an XML photograph that CI systems can develop into a report.
Nota
Remember to call cov.save() before invoking xml_report() to ensure the latest coverage data is written to the data file.
Log in to save chunks.