Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sources not displaying in the coverage.xml file #1555

Open
etaylork opened this issue Feb 10, 2023 · 5 comments
Open

sources not displaying in the coverage.xml file #1555

etaylork opened this issue Feb 10, 2023 · 5 comments
Labels
bug Something isn't working good first This could be a good first contribution

Comments

@etaylork
Copy link

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 etaylork added bug Something isn't working needs triage labels Feb 10, 2023
@etaylork
Copy link
Author

Hello has there been any update on this issue?

@nedbat
Copy link
Owner

nedbat commented Mar 14, 2023

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

@etaylork
Copy link
Author

etaylork commented Apr 4, 2023

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

@nedbat
Copy link
Owner

nedbat commented Apr 24, 2023

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

@nedbat nedbat added the good first This could be a good first contribution label Apr 24, 2023
@kevin-brown
Copy link
Contributor

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 #1608.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first This could be a good first contribution
Projects
None yet
Development

No branches or pull requests

3 participants