Skip to content

Commit ec344d8

Browse files
authored
Merge pull request #459 from dsegan/introduce-reset-cov-option
Implement --cov-reset option that resets accumulated --cov directorie…
2 parents f748779 + fb2c67e commit ec344d8

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

docs/config.rst

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ The complete list of command line options is:
6666
False
6767
--no-cov Disable coverage report completely (useful for
6868
debuggers). Default: False
69+
--cov-reset Reset cov sources accumulated in options so far.
70+
Mostly useful for scripts and configuration files.
6971
--cov-fail-under=MIN Fail if the total coverage is less than MIN.
7072
--cov-append Do not delete coverage but append to current. Default:
7173
False

src/pytest_cov/plugin.py

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ def pytest_addoption(parser):
9191
nargs='?', const=True, dest='cov_source',
9292
help='Path or package name to measure during execution (multi-allowed). '
9393
'Use --cov= to not do any source filtering and record everything.')
94+
group.addoption('--cov-reset', action='store_const', const=[], dest='cov_source',
95+
help='Reset cov sources accumulated in options so far. ')
9496
group.addoption('--cov-report', action=StoreReport, default={},
9597
metavar='TYPE', type=validate_report,
9698
help='Type of report to generate: term, term-missing, '

tests/test_pytest_cov.py

+27
Original file line numberDiff line numberDiff line change
@@ -1998,6 +1998,33 @@ def test_double_cov2(testdir):
19981998
assert result.ret == 0
19991999

20002000

2001+
def test_cov_reset(testdir):
2002+
script = testdir.makepyfile(SCRIPT_SIMPLE)
2003+
result = testdir.runpytest('-v',
2004+
'--assert=plain',
2005+
'--cov=%s' % script.dirpath(),
2006+
'--cov-reset',
2007+
script)
2008+
2009+
assert 'coverage: platform' not in result.stdout.str()
2010+
2011+
2012+
def test_cov_reset_then_set(testdir):
2013+
script = testdir.makepyfile(SCRIPT_SIMPLE)
2014+
result = testdir.runpytest('-v',
2015+
'--assert=plain',
2016+
'--cov=%s' % script.dirpath(),
2017+
'--cov-reset',
2018+
'--cov=%s' % script.dirpath(),
2019+
script)
2020+
2021+
result.stdout.fnmatch_lines([
2022+
'*- coverage: platform *, python * -*',
2023+
'test_cov_reset_then_set* %s*' % SCRIPT_SIMPLE_RESULT,
2024+
'*1 passed*'
2025+
])
2026+
2027+
20012028
@pytest.mark.skipif('sys.platform == "win32" and platform.python_implementation() == "PyPy"')
20022029
def test_cov_and_no_cov(testdir):
20032030
script = testdir.makepyfile(SCRIPT_SIMPLE)

0 commit comments

Comments
 (0)