Skip to content

Commit fb2c67e

Browse files
author
Danilo Šegan
committed
Implement --cov-reset option that resets accumulated --cov directories to an empty list.
1 parent daf54e7 commit fb2c67e

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

docs/config.rst

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ def pytest_addoption(parser):
7070
nargs='?', const=True, dest='cov_source',
7171
help='Path or package name to measure during execution (multi-allowed). '
7272
'Use --cov= to not do any source filtering and record everything.')
73+
group.addoption('--cov-reset', action='store_const', const=[], dest='cov_source',
74+
help='Reset cov sources accumulated in options so far. ')
7375
group.addoption('--cov-report', action=StoreReport, default={},
7476
metavar='TYPE', type=validate_report,
7577
help='Type of report to generate: term, term-missing, '

tests/test_pytest_cov.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,6 +1999,33 @@ def test_double_cov2(testdir):
19991999
assert result.ret == 0
20002000

20012001

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

0 commit comments

Comments
 (0)