Skip to content

warn specific classes #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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