Skip to content

Commit d810c65

Browse files
authored
warn specific classes (#361)
* warn specific classes * Update src/pytest_cov/plugin.py * Update src/pytest_cov/compat.py * Update src/pytest_cov/compat.py * Update src/pytest_cov/compat.py * Update src/pytest_cov/plugin.py * Update src/pytest_cov/plugin.py
1 parent 2b6660e commit d810c65

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/pytest_cov/plugin.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ class CoverageError(Exception):
1414
"""Indicates that our coverage is too low"""
1515

1616

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+
1731
def validate_report(arg):
1832
file_choices = ['annotate', 'html', 'xml']
1933
term_choices = ['term', 'term-missing']
@@ -282,7 +296,7 @@ def pytest_runtestloop(self, session):
282296
message = 'Failed to generate report: %s\n' % exc
283297
session.config.pluginmanager.getplugin("terminalreporter").write(
284298
'WARNING: %s\n' % message, red=True, bold=True)
285-
warnings.warn(pytest.PytestWarning(message))
299+
warnings.warn(CovReportWarning(message))
286300
self.cov_total = 0
287301
assert self.cov_total is not None, 'Test coverage should never be `None`'
288302
if self._failed_cov_total():
@@ -294,7 +308,7 @@ def pytest_terminal_summary(self, terminalreporter):
294308
if self.options.no_cov_should_warn:
295309
message = 'Coverage disabled via --no-cov switch!'
296310
terminalreporter.write('WARNING: %s\n' % message, red=True, bold=True)
297-
warnings.warn(pytest.PytestWarning(message))
311+
warnings.warn(CovDisabledWarning(message))
298312
return
299313
if self.cov_controller is None:
300314
return

0 commit comments

Comments
 (0)