codecov-python icon indicating copy to clipboard operation
codecov-python copied to clipboard

`.coveragerc` vs. `tox.ini`

Open Peque opened this issue 6 years ago • 6 comments

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 runs codecov 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 runs codecov 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 in tox.ini
  • Should not codecov read that file by default?

Peque avatar Mar 23 '18 13:03 Peque

Did you manage to get this solved? :(

Ademord avatar Jun 13 '18 08:06 Ademord

@Ademord Sadly no. I am still using a separate .coveragerc file and, as you can see, got no response from @codecov. :confused:

Peque avatar Jun 13 '18 11:06 Peque

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 avatar Jun 13 '18 11:06 Ademord

@Ademord Yeah, it seems it does not apply to my use case, but thanks for sharing! :blush:

Peque avatar Jun 13 '18 14:06 Peque

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"

mpurnell1 avatar Oct 30 '22 03:10 mpurnell1

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

ssbarnea avatar Nov 26 '22 00:11 ssbarnea