XML reporting: coverage xml

The xml command writes coverage data to a “coverage.xml” file in a format compatible with Cobertura.

$ coverage xml --help
Usage: coverage xml [options] [modules]

Generate an XML report of coverage results.

Options:
  --data-file=INFILE    Read coverage data for report generation from this
                        file. Defaults to '.coverage'. [env: COVERAGE_FILE]
  --fail-under=MIN      Exit with a status of 2 if the total coverage is less
                        than MIN.
  -i, --ignore-errors   Ignore errors while reading source files.
  --include=PAT1,PAT2,...
                        Include only files whose paths match one of these
                        patterns. Accepts shell-style wildcards, which must be
                        quoted.
  --omit=PAT1,PAT2,...  Omit files whose paths match one of these patterns.
                        Accepts shell-style wildcards, which must be quoted.
  -o OUTFILE            Write the XML report to this file. Defaults to
                        'coverage.xml'
  -q, --quiet           Don't print messages about what is happening.
  --skip-empty          Skip files with no code.
  --debug=OPTS          Debug options, separated by commas. [env:
                        COVERAGE_DEBUG]
  -h, --help            Get help on this command.
  --rcfile=RCFILE       Specify configuration file. By default '.coveragerc',
                        'setup.cfg', 'tox.ini', and 'pyproject.toml' are
                        tried. [env: COVERAGE_RCFILE]

You can specify the name of the output file with the -o switch.

Other common reporting options are described above in Reporting.

To include complete file paths in the output file, rather than just the file name, use [include] vs [source] in your “.coveragerc” file.

For example, use this:

[run]
include =
    foo/*
    bar/*

which will result in

<class filename="bar/hello.py">
<class filename="bar/baz/hello.py">
<class filename="foo/hello.py">

in place of this:

[run]
source =
    foo
    bar

which may result in

<class filename="hello.py">
<class filename="baz/hello.py">

These options can also be set in your .coveragerc file. See Configuration: [xml].