@@ -14,6 +14,20 @@ class CoverageError(Exception):
14
14
"""Indicates that our coverage is too low"""
15
15
16
16
17
+ class PytestCovWarning (pytest .PytestWarning ):
18
+ """
19
+ The base for all pytest-cov warnings, never raised directly
20
+ """
21
+
22
+
23
+ class CovDisabledWarning (PytestCovWarning ):
24
+ """Indicates that Coverage was manually disabled"""
25
+
26
+
27
+ class CovReportWarning (PytestCovWarning ):
28
+ """Indicates that we failed to generate a report"""
29
+
30
+
17
31
def validate_report (arg ):
18
32
file_choices = ['annotate' , 'html' , 'xml' ]
19
33
term_choices = ['term' , 'term-missing' ]
@@ -282,7 +296,7 @@ def pytest_runtestloop(self, session):
282
296
message = 'Failed to generate report: %s\n ' % exc
283
297
session .config .pluginmanager .getplugin ("terminalreporter" ).write (
284
298
'WARNING: %s\n ' % message , red = True , bold = True )
285
- warnings .warn (pytest . PytestWarning (message ))
299
+ warnings .warn (CovReportWarning (message ))
286
300
self .cov_total = 0
287
301
assert self .cov_total is not None , 'Test coverage should never be `None`'
288
302
if self ._failed_cov_total ():
@@ -294,7 +308,7 @@ def pytest_terminal_summary(self, terminalreporter):
294
308
if self .options .no_cov_should_warn :
295
309
message = 'Coverage disabled via --no-cov switch!'
296
310
terminalreporter .write ('WARNING: %s\n ' % message , red = True , bold = True )
297
- warnings .warn (pytest . PytestWarning (message ))
311
+ warnings .warn (CovDisabledWarning (message ))
298
312
return
299
313
if self .cov_controller is None :
300
314
return
0 commit comments