-
-
Notifications
You must be signed in to change notification settings - Fork 436
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
Coverage.py fails to omit *third-party* coverage in a nested venv from the same implicit namespace package #1869
Comments
This is a workaround for a coveragepy imperfection where it mistakenly treats same-namespace third-party modules as same-project ones: nedbat/coveragepy#1869. Refs: * nedbat/coveragepy#876 * nedbat/coveragepy#905 * nedbat/coveragepy@27d8255 * nedbat/coveragepy@5c2f614
This is a workaround for a coveragepy imperfection where it mistakenly treats same-namespace third-party modules as same-project ones: nedbat/coveragepy#1869. Refs: * nedbat/coveragepy#876 * nedbat/coveragepy#905 * nedbat/coveragepy@27d8255 * nedbat/coveragepy@5c2f614
Nope. It only appeared to be a full workaround, but it's not. It does what I expected in the local HTML/XML reports, but excludes all of the |
I ended up changing that to a granular omit =
.tox/*/lib/pypy*/site-packages/awx_plugins/interfaces/**
.tox/*/lib/python*/site-packages/awx_plugins/interfaces/**
.tox\*\Lib\site-packages\awx_plugins\interfaces\** for now, but I don't understand why running the same command in the CI and locally would produce different coverage reports. It seems like the environment somehow influences how |
Describe the bug
I have a case when I get unexpected coverage measurements from a tox-managed virtualenv existing within the source tree. Coveragepy is invoked via
pytest-cov
but all configuration is in coveragerc so I'm pretty sure this issue belongs here.This reminds me of #876 and #905. Having stared at 0285af9 and 5c2f614, I concluded that the fixes are still imperfect.
The reproducers in those issues showcased regular non-namespaces packages, which is why it wasn't on anybody's radar, I think. But I'm sure my case is legit too.
In the example below,
awx_plugins
is the namespace. The dependency is theawx_plugins.interfaces
importable and the project itself containsawx_plugins.credentials
andawx_plugins.inventory
.The project's files are under
src/awx_plugins/{credentials,inventory}/*.py
andtests/*.py
. The dependecy hassrc/awx_plugins/interfaces/*.py
in the repo, but all are installed side-by-side as.tox/py/lib/python3.13/site-packages/awx_plugins/{credentials,interfaces,inventory}/*.py
..tox/py/lib/python3.13/site-packages/awx_plugins/__init__.py
does not exist..tox/py/lib/python3.13/site-packages/awx_plugins/{credentials,interfaces,inventory}/__init__.py
do not exist either.The project is configured with
which maps all the project-local source files properly (which is visible in the report correctly). The third-party ones remain unmatched and show up with site-packages paths.
There's also
The generic paths and namespaces effectively give me the ability to copy the good coveragerc file over into similar packages of the same namespace and folder layout. This is intentional.
I'm almost sure changing
source_pkgs
to listawx_plugins.credentials
andawx_plugins.inventory
would limit what ends up in the report but that's not something I want given that I wish to have a reusable config across an ecosystem of similar projects (i.e. plugins to something else).I've tested that adding
omit = .tox/**
is a functional workaround, following the suggestions in other issues.
But ultimately, I believe that this is a bug fixable within coveragepy and I shouldn't have to keep the
omit
settings in my configs.To Reproduce
What version of Python are you using? A range of Python 3.11-3.13, I'm pretty sure the problem is agnostic, though.
What version of coverage.py shows the problem?
👉 click to unfold 👈
What versions of what packages do you have installed?
👉 click to unfold 👈
What code shows the problem? ansible/awx-plugins@8ea0766
What commands should we run to reproduce the problem?
That shows a couple of files under
.tox/py/lib/python3.13/site-packages/awx_plugins/interfaces/**
. They should not be listed.Expected behavior
Coveragepy should not collect coverage in third-party modules from the same implicit namespace, installed in the same virtualenv.
Additional context
The concrete example is inspectable at https://app.codecov.io/gh/ansible/awx-plugins/commit/8ea07661f9da09dedaa52b569978c448fb871931/tree?flags%5B0%5D=pytest. The pre-selected
pytest
flag is what you want to have selected at all times since there's also MyPy coverage that's overlayed if you deselect it.The text was updated successfully, but these errors were encountered: