Skip to content

Commit

Permalink
Merge pull request #459 from dsegan/introduce-reset-cov-option
Browse files Browse the repository at this point in the history
Implement --cov-reset option that resets accumulated --cov directorie…
  • Loading branch information
ionelmc authored Sep 9, 2021
2 parents f748779 + fb2c67e commit ec344d8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
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 @@ -91,6 +91,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 @@ -1998,6 +1998,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

0 comments on commit ec344d8

Please sign in to comment.