`codecov` not reporting expected coverage when using package name

Hi,
I am working on a project called NiQuery hosted on GitHub. I am confused about the coverage report.

I was surprised to see that the module run.py had 0% coverage.

I thought that this may be related to the use of click commands by the run.py module, and some sort of interaction that I was missing between components, or the way things are imported. However, I have realized that there are such as filtering.py and featuring.py that do not depend on click for which the reported coverage is also 0%. Again, they are extensively tested.

In the relevant command in my tox.ini file, if I change the package name for the location of the files for the cov option:

commands =
  pytest -sv --doctest-modules --cov niquery --cov-report xml \
  --junitxml=test-results.xml -v src test {posargs:-n auto}

to

commands =
  pytest -sv --doctest-modules --cov src/niquery --cov-report xml \
  --junitxml=test-results.xml -v src test {posargs:-n auto}

then the coverage increases significantly (from 0% to 82%, 98% and 100%)

It can also be reproduced simply calling pytest:

pytest --cov niquery

vs

pytest --cov src/niquery

I contribute to other projects that have a very similar structure and use the package name for the cov option and do not have this issues.

I would like to stick to the philosophy of using the package name for the cov option, unless this is wrong, as it is used by other projects within the organization.

I am wondering what am I doing wrong here.

Thank you.

(I saw your coverage.py issue, but thought it would be useful to continue the discussion here.)

It looks like coverage.py thinks your files are not meant to be measured.

I would switch on some debugging to see what is happening. Coverage.py has a number of debugging options that can help. Try setting COVERAGE_DEBUG=trace in the environment. That will print each decision about what files to trace or not, and why.

I think this may be a distinction between the original source files in src/ and the installed copy in .tox/.../site-packages/. Or at least, that’s how it sounds.

To ensure good reporting, my projects now set paths config, like so:

[tool.coverage.paths]
source = [
    "src/",
    "*/site-packages/",
]

I know pytest-cov automatically sets some things, but I’ve stopped using it since coverage run -m pytest works for me, and I’d rather have direct control over the config.

I’m not certain this is the issue in this case, but it sounds similar to what I’ve experienced when I test an installed copy of a package and try to report on src/.