Skip to content

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

Open
@dsegan

Description

@dsegan

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: #459

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions