3

my python project is composed of several different packages

main_dir
|- package_1
|- package_2
|_ package_3

i'm testing each package separately with pytest and pytest-cov

python -m pytest package_1\tests --junitxml package_1\test_result.xml --cov package_1 --cov-branch --cov-report xml:package_1\test_coverage.xml
python -m pytest package_2\tests --junitxml package_2\test_result.xml --cov package_2 --cov-branch --cov-report xml:package_2\test_coverage.xml
python -m pytest package_3\tests --junitxml package_3\test_result.xml --cov package_3 --cov-branch --cov-report xml:package_3\test_coverage.xml

this produces separate test_coverage.xml and .coverage file for each package

i want to merge the test coverage files into one xml file

what i did:

coverage combine package_1\.coverage package_2\.coverage package_3\.coverage

which works, generating a new .coverage file in my working directory, but then if I run:

coverage xml .coverage

i get this error:

Couldn't parse 'C:\Users\xxxx\Documents\git\main_dir\.coverage' as Python source: 'EOF in multi-line statement' at line 6580

Any idea on how I can achieve what i want? Is it possible to combine the xml files directly into one without passing through the .coverage files?

Many thanks

1 Answer 1

0

The coverage xml command doesn't take the name of a data file as an argument. The arguments are module names:

    $ 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]

A plain coverage xml command should be enough. Does it not work?

Sign up to request clarification or add additional context in comments.

1 Comment

if i try: coverage xml --data-file=.coverage or simply: coverage xml i get: No data to report

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.