pytest-cov icon indicating copy to clipboard operation
pytest-cov copied to clipboard

Introduce --cov-reset option to reset --cov=* values set so far

Open dsegan opened this issue 4 years ago • 0 comments

It is sometimes useful to "reset" all the --cov=X options passed in "so far", eg.

  pytest --cov=app --cov-reset --cov=app/module

would only check for coverage on app/module instead of checking the coverage on all modules in app.

My particular use case is to allow getting coverage from both local pytest and tox runs (tox is slower :)), yet keep tox using the installed package:

pytest.ini:

[pytest]
addopts = . --cov=package --cov-report=term-missing

tox.ini:

[tox]
envlist = py37,py38,py39

[testenv]
commands = 
    pytest . --cov-reset --cov={envsitepackagesdir}/package

Without the reset option, tox runs will include coverage on both the installed package and local copy (which is always zero).

As a bonus, such a simple implementation of --cov-reset could even be used to replace --no-cov altogether (the only requirement being that --cov-reset has to go after all the --cov options), so it's more flexible and a much simpler implementation. However, one would have to think carefully about all the use cases for no-cov (debuggers are mentioned)

Here's a pull request if you think this is worthwhile: https://github.com/pytest-dev/pytest-cov/pull/459

dsegan avatar Mar 25 '21 14:03 dsegan