I don’t know if it’s the way coverage.py works or ...
# general
r
I don’t know if it’s the way coverage.py works or it’s the pants integration but the coverage doesn’t include those modules which aren’t imported by the tests. I thought it would look at all the source files and then compare it with the tests inside the test files.
So if I don’t write any tests, the coverage would be 100%? 😄
I think it’s the issue with the pants integration. I ran it outside directly using coverage and it looks at all the source files under a provided directory.
h
Yeah, coverage expects to have a global view of all sources, which is at odds with the monorepo way of doing things incrementally (and also doesn't really scale).
We'd have to copy all the sources into the sandbox
r
I am actually filtering currently. So it should only copy all the source files inside these directories.
So what works is setting the
source
option inside the config file. I am using
pyproject.toml
. So I set
Copy code
[tool.coverage.run]
omit = ["*/tests/*"]
source = [
  "source1",
  "source2",
  "source3",
]
Actually I spoke too soon. This doesn’t work either. Not sure what’s going on since pants is also using
pytest --cov=source ..
when the filter option is provided. But the results don’t match with running pytest locally with
--cov
option. It does include all the source files inside the source directory. In case of pants that doesn’t happen.