Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --cov-omit option #373

Open
roipoussiere opened this issue Dec 16, 2019 · 22 comments
Open

Add --cov-omit option #373

roipoussiere opened this issue Dec 16, 2019 · 22 comments

Comments

@roipoussiere
Copy link

Similar to --omit option in coverage.py, this option could be used to ignore some specific files.

Ignoring files can be done with a .coveragerc file, but many developers don't want to add an other file in their project root folder just to ignore one or two folder during the coverage analysis.

related to #193

@nedbat
Copy link
Collaborator

nedbat commented Dec 16, 2019

Coverage will read settings from setup.cfg, or tox.ini, or pyproject.toml files. There's no need to add another option to an already cluttered command line.

@nedbat nedbat closed this as completed Dec 16, 2019
@roipoussiere
Copy link
Author

Yes but it can be annoying to create a configuration file only to add a simple option to the command.

@nedbat
Copy link
Collaborator

nedbat commented Jan 17, 2020

@roipoussiere You don't have any of these files? setup.cfg, tox.ini, pyproject.toml?

@roipoussiere
Copy link
Author

No, any of them. I would like to keep my root tree as clean as possible.

@nedbat
Copy link
Collaborator

nedbat commented Jan 31, 2020

I understand that impulse. We would like to keep our plugin as simple as possible.

@MichaelKim0407
Copy link

I think this suggestion is completely valid. Sometimes I just want to try a command to see if something works, without creating a config file. That's the whole point of command line arguments.

If I need to use the same configuration repeatedly, I'll know myself to create a config file. I don't need you to dictate that I should always create a config file.

And it's not like this suggestion is asking for a very complex argument. Whatever you already support in the config file, just put it in the command line. With your logic (to keep it simple) you may as well argue that your plugin shouldn't support any command line argument at all.

@The-Compiler
Copy link
Member

@nedbat How would you feel about having a general "coverage option" commandline argument, similar to pytest's -o / --override-ini? That way, people could still do something like --cov-opt run.omit resources.py etc., but the plugin doesn't need to play catch up if there are new arguments/options in coverage.py?

@MichaelKim0407
Copy link

@The-Compiler I think your suggestion somewhat misses the point:

  1. The reason for this feature request is that I don't want to create a config file

  2. It's not playing catch up. pytest-cov already supports it. It's just a matter of adding it in the command line options.

@The-Compiler
Copy link
Member

@The-Compiler I think your suggestion somewhat misses the point

It does?

The reason for this feature request is that I don't want to create a config file

Which is why I proposed an option which lets you set coverage config options without having a config file.

It's not playing catch up. pytest-cov already supports it. It's just a matter of adding it in the command line options.

How so? From what I can tell, pytest-cov does not handle omit in any way. Having to play catch-up because the plugin is rather complex has been a problem in the past (see #337 for a longer discussion), hence my proposal of adding an option which works in a more general way and doesn't need the plugin to update when there are changes in coverage.py.

@nedbat nedbat changed the title Add --cov-ommit option Add --cov-omit option Mar 25, 2020
@MichaelKim0407
Copy link

MichaelKim0407 commented Mar 25, 2020

@The-Compiler ok nevermind, my bad.

I thought pytest-cov already supports it because it's available in the config file. But from what you are saying, it's coverage.py reading that config file directly?

@roipoussiere
Copy link
Author

The discussion continues here with good arguments but the issue is still closed. Is it possible to re-open it?

@ionelmc
Copy link
Member

ionelmc commented May 10, 2020

It is certainly possible but whomever reopens it should pledge to maintain an increasing cornucopia of options and switches. That person isn't me and I don't see anyone offering their time when clearly there are alternatives to another cli option.

@MichaelKim0407
Copy link

MichaelKim0407 commented May 10, 2020 via email

@ionelmc
Copy link
Member

ionelmc commented May 10, 2020

I'm not interested. I was only alluding that maintenance is scarce.

@The-Compiler
Copy link
Member

@ionelmc How do you feel about my proposal in #373 (comment)? That could possibly even replace any existing commandline options which just get passed through to coverage.py currently. However, it means coverage.py would need some kind of API to pass additional options (while still reading its config file).

@ionelmc
Copy link
Member

ionelmc commented May 10, 2020

I guess it could be acceptable if that makes it possible to remove other cli arguments.

@philipjames44
Copy link

This would be a really nice QOL feature

@cygnus2048
Copy link

Yeah, I've been waiting for this for several years now and still nothing. Instead in every one of my projects I have to hack the shared config file that all my projects use with multiple sed commands. Sad.

@nedbat
Copy link
Collaborator

nedbat commented Mar 14, 2023

@cygnus2048 I don't understand how you are using sed on a shared config file? How does that help you omit files?

@mikeloomisgg
Copy link

I believe the dev spoke past the original ask here. If you came to this thread looking for a solution to be able to specify both source files to include in coverage, and also paths to omit from coverage, you should use the [tool.coverage] metadata in your pyproject.toml. You do not need to create a .coveragerc file, and doing such would obviously not be canonical in modern python.

Here is an example for adding omit options to your pyproject.toml:

[tool.pytest.ini_options]
testpaths = ["tests"]
norecursedirs = ["dist", "build", "dev", "typings"]
addopts = ["--cov=./"]

[tool.coverage.run]
source = ["./*"]
omit = ["dev/*", "tests/*"]

This satisfies canonical python projects, since all of them should be using a single pyproject.toml to define their project's metadata.

@cygnus2048
Copy link

I have a common coverage config file that is copied into each project during the build. As one of the final steps of the build I run multiple sed commands to add to the "omit" section of that config file. It works, but less than desirable. Having a command line arg would make this much simpler and cleaner. Thanks.

@mattvonrocketstein
Copy link

for projects that have multiple test-suites (say units vs smoke-testing) using a base coverage config file + a few extra options would be very nice to have.

more specifically, i want to do things like run unit-tests and omit coverage for __main__.py, because those are covered in a smoke-test suite elsewhere. (suite-coverage will be combined later if all suites are running, but if my work is more focused, it's good to avoid the screen-clutter and cognitive overhead of parsing the irrelevant coverage. plus it's bring down the percentage :)

afaik, currently the best solution here is to have multiple .coveragerc's where the vast majority of the content is redundant and then has to be kept in sync. i imagine this scenario is fairly common; just wanted to share that everyone who is interested in this is not trying to completely avoid config files and put everything on a CLI invocation. i have and enjoy config files!, but i don't want half a dozen for simple tasks, so base configs + CLI overrides seems like the way to go.

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

No branches or pull requests

9 participants