coveragepy icon indicating copy to clipboard operation
coveragepy copied to clipboard

sources not displaying in the coverage.xml file

Open etaylork opened this issue 2 years ago • 8 comments

Describe the bug In the generated coverage.xml report the tag is not populating the sources path.

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.

etaylork avatar Feb 10 '23 00:02 etaylork

Hello has there been any update on this issue?

etaylork avatar Mar 14 '23 00:03 etaylork

@etaylork Can you provide us with a way to reproduce the issue?

nedbat avatar Mar 14 '23 09:03 nedbat

@nedbat I provide the details in the description section of my post is there some more information that you require?

etaylork avatar Apr 04 '23 23:04 etaylork

Ideally, you would have a repo with the exact code that demonstrates the failure.

nedbat avatar Apr 24 '23 14:04 nedbat

I'm fairly certain the instructions to reproduce are invalid, given the following:

  • The config indicates that the source is app while having two exclusions covering it (app and app/app), it's unclear what the overall project structure is as a result.
  • The pytest-cov command given overrides the src to be app (via --cov=app) but also disables the XML reporter in favor of the term-missing reporter, so no XML report would be generated
  • The expected coverage.xml snippet includes an absolute <source> which is not possible when relative_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.

kevin-brown avatar Apr 24 '23 17:04 kevin-brown