Skip to content

Commit beef5f0

Browse files
committed
make --cov a flag per default
1 parent 241b72b commit beef5f0

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

pytest-cov/pytest_cov.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
def pytest_addoption(parser):
1212
"""Add options to control coverage."""
1313

14-
group = parser.getgroup('coverage reporting with distributed testing '
15-
'support')
16-
group.addoption('--cov', action='append', default=[], metavar='path',
17-
dest='cov_source',
14+
group = parser.getgroup(
15+
'cov', 'coverage reporting with distributed testing support')
16+
17+
group.addoption('--cov', action='append', nargs='?', dest='cov',
18+
const=True, default=[],
19+
help='Enable coverage plugin.')
20+
group.addoption('--cov-source', action='append', default=[],
21+
metavar='path', dest='cov_source',
1822
help='measure coverage for filesystem path '
1923
'(multi-allowed)')
2024
group.addoption('--cov-report', action='append', default=[],
@@ -35,14 +39,23 @@ def pytest_addoption(parser):
3539
@pytest.mark.tryfirst
3640
def pytest_load_initial_conftests(early_config, parser, args):
3741
ns = parser.parse_known_args(args)
38-
if ns.cov_source:
42+
if ns.cov and ns.cov != [True]:
43+
print ('Deprecation warning: --cov shouldn\'t be used '
44+
'with additional source arguments anymore. Use '
45+
'--cov-source instead.')
46+
ns.cov_source.extend(ns.cov)
47+
48+
if not ns.cov_source:
49+
ns.cov_source = None
50+
51+
if ns.cov:
3952
plugin = CovPlugin(ns, early_config.pluginmanager)
4053
early_config.pluginmanager.register(plugin, '_cov')
4154

4255

4356
def pytest_configure(config):
4457
"""Activate coverage plugin if appropriate."""
45-
if config.getvalue('cov_source'):
58+
if config.getvalue('cov'):
4659
if not config.pluginmanager.hasplugin('_cov'):
4760
plugin = CovPlugin(config.option, config.pluginmanager,
4861
start=False)

0 commit comments

Comments
 (0)