codecov-python
codecov-python copied to clipboard
`.coveragerc` vs. `tox.ini`
Initial setup
I have a .coveragerc
file like:
[report]
exclude_lines =
def __repr__
I run my tests with tox
which in turn runs pytest
with pytest-cov
, which means my tox.ini
file looks like this:
[testenv]
deps =
pytest
pytest-cov
commands = pytest --cov
Then:
- When running
tox
in my machine the showed report correctly excludes those lines. - When the CI service runs
tox
, it also shows the correct report, with those lines excluded. - Just after running
tox
, the CI service runscodecov
and the report uploaded to Codecov is also correct.
Broken setup
Now I remove .coveragerc
file and move those lines to tox.ini
:
[coverage:report]
exclude_lines =
def __repr__
Then:
- When running
tox
in my machine the showed report correctly excludes those lines. - When the CI service runs
tox
, it also shows the correct report, with those lines excluded. - Just after running
tox
, the CI service runscodecov
and the report uploaded to Codecov, this time, differs. It does not have those excluded lines, so they are reported as not covered.
Questions
- Why is this happening?
- Is there any way I could fix that?
- Is there an option in
codecov
to specify the coverage configuration is intox.ini
- Should not
codecov
read that file by default?
Did you manage to get this solved? :(
@Ademord Sadly no. I am still using a separate .coveragerc
file and, as you can see, got no response from @codecov. :confused:
I fixed my issue. My use case worked when I used:
[coverage:report]
pragma: no cover
pragma: $envvar cover
where envvar=NO would be set if i wasnt using it 😄 You can look at more details about my case here.
@Ademord Yeah, it seems it does not apply to my use case, but thanks for sharing! :blush:
I'm not sure if this applies to your use case (and also I'm 4 years late), but codecov supports a section in their yaml file (codecov.yml in root directory) called ignore
whcih accepts regex expressions to exclude. Mine looks similar to below to ignore django files
coverage:
status:
project:
default:
threshold: 0.15%
ignore:
- "myProject*"
- "**/admin"
- "**/migrations"
- "**/pycache"
- "**/templatetags"
- "**/tests"
- "**/views"
- "manage.py"
- "**/__init__.py"
- "**/decorators.py"
- "**/fields.py"
- "**/forms.py"
- "**/middleware.py"
- "**/mixins.py"
- "**/sitemaps.py"
- "**/tasks.py"
- "**/urls.py"
- "**/utils"
- "**/errors.py"
I think that the situation it getting worse since almost everyone is moving to pyproject.toml including coveragepy.
I observed that codecov does not load the excludes from the valid codeveragepy config. ansible/ansible-lint@main/pyproject.toml#L13-L24
In my particular case I was interested about exclude_lines