Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

.coveragerc vs. tox.ini #144

Open
Peque opened this issue Mar 23, 2018 · 6 comments
Open

.coveragerc vs. tox.ini #144

Peque opened this issue Mar 23, 2018 · 6 comments

Comments

@Peque
Copy link

Peque commented Mar 23, 2018

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?
@Ademord
Copy link

Ademord commented Jun 13, 2018

Did you manage to get this solved? :(

@Peque
Copy link
Author

Peque commented Jun 13, 2018

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

@Ademord
Copy link

Ademord commented Jun 13, 2018

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.

@Peque
Copy link
Author

Peque commented Jun 13, 2018

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

@thomasrockhu thomasrockhu self-assigned this Nov 29, 2020
@thomasrockhu thomasrockhu removed their assignment Jul 21, 2021
@mpurnell1
Copy link

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"

@ssbarnea
Copy link

ssbarnea commented Nov 26, 2022

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants