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

Implement --cov-reset option that resets accumulated --cov directorie… #459

Merged
merged 1 commit into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ The complete list of command line options is:
False
--no-cov Disable coverage report completely (useful for
debuggers). Default: False
--cov-reset Reset cov sources accumulated in options so far.
Mostly useful for scripts and configuration files.
--cov-fail-under=MIN Fail if the total coverage is less than MIN.
--cov-append Do not delete coverage but append to current. Default:
False
Expand Down
2 changes: 2 additions & 0 deletions src/pytest_cov/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def pytest_addoption(parser):
nargs='?', const=True, dest='cov_source',
help='Path or package name to measure during execution (multi-allowed). '
'Use --cov= to not do any source filtering and record everything.')
group.addoption('--cov-reset', action='store_const', const=[], dest='cov_source',
help='Reset cov sources accumulated in options so far. ')
group.addoption('--cov-report', action=StoreReport, default={},
metavar='TYPE', type=validate_report,
help='Type of report to generate: term, term-missing, '
Expand Down
27 changes: 27 additions & 0 deletions tests/test_pytest_cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -1999,6 +1999,33 @@ def test_double_cov2(testdir):
assert result.ret == 0


def test_cov_reset(testdir):
script = testdir.makepyfile(SCRIPT_SIMPLE)
result = testdir.runpytest('-v',
'--assert=plain',
'--cov=%s' % script.dirpath(),
'--cov-reset',
script)

assert 'coverage: platform' not in result.stdout.str()


def test_cov_reset_then_set(testdir):
script = testdir.makepyfile(SCRIPT_SIMPLE)
result = testdir.runpytest('-v',
'--assert=plain',
'--cov=%s' % script.dirpath(),
'--cov-reset',
'--cov=%s' % script.dirpath(),
script)

result.stdout.fnmatch_lines([
'*- coverage: platform *, python * -*',
'test_cov_reset_then_set* %s*' % SCRIPT_SIMPLE_RESULT,
'*1 passed*'
])


@pytest.mark.skipif('sys.platform == "win32" and platform.python_implementation() == "PyPy"')
def test_cov_and_no_cov(testdir):
script = testdir.makepyfile(SCRIPT_SIMPLE)
Expand Down