bpo-31411: Prevent raising a SystemError in case warnings.onceregistry is not a dictionary. (#3485)

This commit is contained in:
Oren Milman 2017-09-11 09:28:39 +03:00 committed by Serhiy Storchaka
parent 3866d9bbcf
commit 252033d50e
3 changed files with 20 additions and 1 deletions

View file

@ -794,6 +794,17 @@ class _WarningsTests(BaseTest, unittest.TestCase):
self.assertNotIn(b'Warning!', stderr)
self.assertNotIn(b'Error', stderr)
@support.cpython_only
def test_issue31411(self):
# warn_explicit() shouldn't raise a SystemError in case
# warnings.onceregistry isn't a dictionary.
wmod = self.module
with original_warnings.catch_warnings(module=wmod):
wmod.filterwarnings('once')
with support.swap_attr(wmod, 'onceregistry', None):
with self.assertRaises(TypeError):
wmod.warn_explicit('foo', Warning, 'bar', 1, registry=None)
class WarningsDisplayTests(BaseTest):