Skip to content

Commit

Permalink
Merge pull request #9656 from sdhiscocks/suppress_warning_subtype_none
Browse files Browse the repository at this point in the history
Fix issue with warnings without subtype being incorrectly suppressed
  • Loading branch information
tk0miya committed Oct 31, 2021
2 parents cda2663 + e38456d commit 4475dab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion sphinx/util/logging.py
Expand Up @@ -369,7 +369,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

0 comments on commit 4475dab

Please sign in to comment.