Skip to content

Commit

Permalink
warn specific classes (#361)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
graingert authored Jul 25, 2021
1 parent 2b6660e commit d810c65
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/pytest_cov/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ class CoverageError(Exception):
"""Indicates that our coverage is too low"""


class PytestCovWarning(pytest.PytestWarning):
"""
The base for all pytest-cov warnings, never raised directly
"""


class CovDisabledWarning(PytestCovWarning):
"""Indicates that Coverage was manually disabled"""


class CovReportWarning(PytestCovWarning):
"""Indicates that we failed to generate a report"""


def validate_report(arg):
file_choices = ['annotate', 'html', 'xml']
term_choices = ['term', 'term-missing']
Expand Down Expand Up @@ -282,7 +296,7 @@ def pytest_runtestloop(self, session):
message = 'Failed to generate report: %s\n' % exc
session.config.pluginmanager.getplugin("terminalreporter").write(
'WARNING: %s\n' % message, red=True, bold=True)
warnings.warn(pytest.PytestWarning(message))
warnings.warn(CovReportWarning(message))
self.cov_total = 0
assert self.cov_total is not None, 'Test coverage should never be `None`'
if self._failed_cov_total():
Expand All @@ -294,7 +308,7 @@ def pytest_terminal_summary(self, terminalreporter):
if self.options.no_cov_should_warn:
message = 'Coverage disabled via --no-cov switch!'
terminalreporter.write('WARNING: %s\n' % message, red=True, bold=True)
warnings.warn(pytest.PytestWarning(message))
warnings.warn(CovDisabledWarning(message))
return
if self.cov_controller is None:
return
Expand Down

0 comments on commit d810c65

Please sign in to comment.