pytest-cov
pytest-cov copied to clipboard
Add --cov-omit option
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
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.
Yes but it can be annoying to create a configuration file only to add a simple option to the command.
@roipoussiere You don't have any of these files? setup.cfg, tox.ini, pyproject.toml?
No, any of them. I would like to keep my root tree as clean as possible.
I understand that impulse. We would like to keep our plugin as simple as possible.
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.
@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?
@The-Compiler I think your suggestion somewhat misses the point:
-
The reason for this feature request is that I don't want to create 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.
@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.
@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?
The discussion continues here with good arguments but the issue is still closed. Is it possible to re-open it?
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.
In that case I think the issue should be reopened so that anyone interested can pick it up. Closed issue means that the maintainer of this project isn't interested.
In other words, if the maintainer of this project is open to this feature being implemented, the issue should be open.
On Sun, May 10, 2020, 11:08 Ionel Cristian Mărieș [email protected] wrote:
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.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/pytest-dev/pytest-cov/issues/373#issuecomment-626366648, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAUCG73DNG3YFTFZMA65LFLRQ3USPANCNFSM4J3H5WLQ .
I'm not interested. I was only alluding that maintenance is scarce.
@ionelmc How do you feel about my proposal in https://github.com/pytest-dev/pytest-cov/issues/373#issuecomment-603779658? 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).
I guess it could be acceptable if that makes it possible to remove other cli arguments.
This would be a really nice QOL feature
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.
@cygnus2048 I don't understand how you are using sed on a shared config file? How does that help you omit files?
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.
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.
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.