11
11
def pytest_addoption (parser ):
12
12
"""Add options to control coverage."""
13
13
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' ,
18
22
help = 'measure coverage for filesystem path '
19
23
'(multi-allowed)' )
20
24
group .addoption ('--cov-report' , action = 'append' , default = [],
@@ -35,14 +39,23 @@ def pytest_addoption(parser):
35
39
@pytest .mark .tryfirst
36
40
def pytest_load_initial_conftests (early_config , parser , args ):
37
41
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 :
39
52
plugin = CovPlugin (ns , early_config .pluginmanager )
40
53
early_config .pluginmanager .register (plugin , '_cov' )
41
54
42
55
43
56
def pytest_configure (config ):
44
57
"""Activate coverage plugin if appropriate."""
45
- if config .getvalue ('cov_source ' ):
58
+ if config .getvalue ('cov ' ):
46
59
if not config .pluginmanager .hasplugin ('_cov' ):
47
60
plugin = CovPlugin (config .option , config .pluginmanager ,
48
61
start = False )
0 commit comments