9
9
from . import compat
10
10
from . import embed
11
11
12
- PYTEST_VERSION = tuple (map (int , pytest .__version__ .split ('.' )[:3 ]))
13
-
14
12
15
13
class CoverageError (Exception ):
16
14
"""Indicates that our coverage is too low"""
@@ -114,8 +112,17 @@ def _prepare_cov_source(cov_source):
114
112
115
113
@pytest .mark .tryfirst
116
114
def pytest_load_initial_conftests (early_config , parser , args ):
115
+ options = early_config .known_args_namespace
116
+ no_cov = options .no_cov_should_warn = False
117
+ for arg in args :
118
+ if arg == '--no-cov' :
119
+ no_cov = True
120
+ elif arg .startswith ('--cov' ) and no_cov :
121
+ options .no_cov_should_warn = True
122
+ break
123
+
117
124
if early_config .known_args_namespace .cov_source :
118
- plugin = CovPlugin (early_config . known_args_namespace , early_config .pluginmanager )
125
+ plugin = CovPlugin (options , early_config .pluginmanager )
119
126
early_config .pluginmanager .register (plugin , '_cov' )
120
127
121
128
@@ -127,7 +134,7 @@ class CovPlugin(object):
127
134
distributed worker.
128
135
"""
129
136
130
- def __init__ (self , options , pluginmanager , start = True ):
137
+ def __init__ (self , options , pluginmanager , start = True , no_cov_should_warn = False ):
131
138
"""Creates a coverage pytest plugin.
132
139
133
140
We read the rc file that coverage uses to get the data file
@@ -275,10 +282,7 @@ def pytest_runtestloop(self, session):
275
282
message = 'Failed to generate report: %s\n ' % exc
276
283
session .config .pluginmanager .getplugin ("terminalreporter" ).write (
277
284
'WARNING: %s\n ' % message , red = True , bold = True )
278
- if PYTEST_VERSION >= (3 , 8 ):
279
- warnings .warn (pytest .PytestWarning (message ))
280
- else :
281
- session .config .warn (code = 'COV-2' , message = message )
285
+ warnings .warn (pytest .PytestWarning (message ))
282
286
self .cov_total = 0
283
287
assert self .cov_total is not None , 'Test coverage should never be `None`'
284
288
if self ._failed_cov_total ():
@@ -287,12 +291,10 @@ def pytest_runtestloop(self, session):
287
291
288
292
def pytest_terminal_summary (self , terminalreporter ):
289
293
if self ._disabled :
290
- message = 'Coverage disabled via --no-cov switch!'
291
- terminalreporter . write ( 'WARNING: %s \n ' % message , red = True , bold = True )
292
- if PYTEST_VERSION >= ( 3 , 8 ):
294
+ if self . options . no_cov_should_warn :
295
+ message = 'Coverage disabled via --no-cov switch!'
296
+ terminalreporter . write ( 'WARNING: %s \n ' % message , red = True , bold = True )
293
297
warnings .warn (pytest .PytestWarning (message ))
294
- else :
295
- terminalreporter .config .warn (code = 'COV-1' , message = message )
296
298
return
297
299
if self .cov_controller is None :
298
300
return
0 commit comments