Skip to content
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

Fix issue with warnings without subtype being incorrectly suppressed #9656

Merged
merged 1 commit into from Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion sphinx/util/logging.py
Expand Up @@ -364,7 +364,8 @@ def is_suppressed_warning(type: str, subtype: str, suppress_warnings: List[str])
target, subtarget = warning_type, None

if target == type:
if (subtype is None or subtarget is None or
if (subtype is None and subtarget is None
or subtarget is None or
subtarget == subtype or subtarget == '*'):
return True

Expand Down
13 changes: 10 additions & 3 deletions tests/test_util_logging.py
Expand Up @@ -131,6 +131,7 @@ def test_is_suppressed_warning():
assert is_suppressed_warning("ref", "option", suppress_warnings) is True
assert is_suppressed_warning("files", "image", suppress_warnings) is True
assert is_suppressed_warning("files", "stylesheet", suppress_warnings) is True
assert is_suppressed_warning("rest", None, suppress_warnings) is False
assert is_suppressed_warning("rest", "syntax", suppress_warnings) is False
assert is_suppressed_warning("rest", "duplicated_labels", suppress_warnings) is True

Expand All @@ -143,33 +144,39 @@ def test_suppress_warnings(app, status, warning):

app.config.suppress_warnings = []
warning.truncate(0)
logger.warning('message0', type='test')
logger.warning('message1', type='test', subtype='logging')
logger.warning('message2', type='test', subtype='crash')
logger.warning('message3', type='actual', subtype='logging')
assert 'message0' in warning.getvalue()
assert 'message1' in warning.getvalue()
assert 'message2' in warning.getvalue()
assert 'message3' in warning.getvalue()
assert app._warncount == 3
assert app._warncount == 4

app.config.suppress_warnings = ['test']
warning.truncate(0)
logger.warning('message0', type='test')
logger.warning('message1', type='test', subtype='logging')
logger.warning('message2', type='test', subtype='crash')
logger.warning('message3', type='actual', subtype='logging')
assert 'message0' not in warning.getvalue()
assert 'message1' not in warning.getvalue()
assert 'message2' not in warning.getvalue()
assert 'message3' in warning.getvalue()
assert app._warncount == 4
assert app._warncount == 5

app.config.suppress_warnings = ['test.logging']
warning.truncate(0)
logger.warning('message0', type='test')
logger.warning('message1', type='test', subtype='logging')
logger.warning('message2', type='test', subtype='crash')
logger.warning('message3', type='actual', subtype='logging')
assert 'message0' in warning.getvalue()
assert 'message1' not in warning.getvalue()
assert 'message2' in warning.getvalue()
assert 'message3' in warning.getvalue()
assert app._warncount == 6
assert app._warncount == 8


def test_warningiserror(app, status, warning):
Expand Down