sources not displaying in the coverage.xml file
Describe the bug
In the generated coverage.xml report the
To Reproduce
What version of Python are you using? python = 3.11 pytest = 4.0.0 coverage.py >= 7.0.0
.coveragerc file
[run]
source = app
omit =
# Ignore tests directory in coverage calculation
app/app/tests/*
app/tests/*
*__init__*
branch = True
relative_files = True
[report]
# Regexes for lines to exclude from consideration
exclude_lines =
pragma: no cover
def __repr__
if self\.debug
raise AssertionError
raise NotImplementedError
if __name__ == .__main__.:
ignore_errors = True
[html]
directory = coverage_html_report
Running with command
pytest --cov=app --cov-config=.coveragerc --cov-report=term-missing
Actual behavior
<?xml version="1.0" ?>
<coverage version="7.1.0" timestamp="1675848032023" lines-valid="2011" lines-covered="1913" line-rate="0.9513" branches-valid="444" branches-covered="375" branch-rate="0.8446" complexity="0">
<!-- Generated by coverage.py: https://coverage.readthedocs.io -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources>
<source></source>
</sources>
<packages>
<package name="alembic" line-rate="0.8571" branch-rate="0.75" complexity="0">
<classes>
<class name="conftest.py" filename="alembic/conftest.py" complexity="0" line-rate="0.9091" branch-rate="1">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="2" hits="1"/>
<line number="3" hits="1"/>
<line number="4" hits="1"/>
<line number="7" hits="1"/>
<line number="8" hits="1"/>
<line number="10" hits="1"/>
<line number="11" hits="1" branch="true" condition-coverage="100% (2/2)"/>
<line number="12" hits="0"/>
<line number="13" hits="0"/>
<line number="16" hits="1"/>
<line number="17" hits="1"/>
<line number="18" hits="1"/>
<line number="19" hits="1"/>
Expected behavior
<?xml version="1.0" ?>
<coverage version="6.5.0" timestamp="1675984773687" lines-valid="2042" lines-covered="1945" line-rate="0.9525" branches-valid="452" branches-covered="385" branch-rate="0.8518" complexity="0">
<!-- Generated by coverage.py: https://coverage.readthedocs.io -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources>
<source>/home/runner/work/contract-service/contract-service/app</source>
</sources>
<packages>
<package name="alembic" line-rate="0.8571" branch-rate="0.75" complexity="0">
<classes>
<class name="conftest.py" filename="alembic/conftest.py" complexity="0" line-rate="0.9091" branch-rate="1">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="2" hits="1"/>
<line number="3" hits="1"/>
<line number="4" hits="1"/>
<line number="7" hits="1"/>
<line number="8" hits="1"/>
<line number="10" hits="1"/>
<line number="11" hits="1" branch="true" condition-coverage="100% (2/2)"/>
Additional context This issue is only happening for all coverage.py versions >= 7.0.0 where I cannot get the sources path to display in the coverage.xml file. The tests are running in docker containers.
Hello has there been any update on this issue?
@etaylork Can you provide us with a way to reproduce the issue?
@nedbat I provide the details in the description section of my post is there some more information that you require?
Ideally, you would have a repo with the exact code that demonstrates the failure.
I'm fairly certain the instructions to reproduce are invalid, given the following:
- The config indicates that the source is
appwhile having two exclusions covering it (appandapp/app), it's unclear what the overall project structure is as a result. - The
pytest-covcommand given overrides thesrcto beapp(via--cov=app) but also disables the XML reporter in favor of theterm-missingreporter, so no XML report would be generated - The expected
coverage.xmlsnippet includes an absolute<source>which is not possible whenrelative_files=True. Additionally the config itself mentions modules not implied by the config that was given.
If I had to read in between the lines, the given source actually includes a trailing slash and is fixed by the "possibly unreported bug" in https://github.com/nedbat/coveragepy/pull/1608.