diff options
author | Victor Stinner <vstinner@redhat.com> | 2018-05-15 18:42:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-15 18:42:12 (GMT) |
commit | b056562860c227bad2e0ba7cd3130e115c007768 (patch) | |
tree | 52e5caee0ef0339c549b8ac11b8afad64b45aa3e /Lib | |
parent | 8709b236fc997077d24b4802320db287640f82e2 (diff) | |
download | cpython-b056562860c227bad2e0ba7cd3130e115c007768.zip cpython-b056562860c227bad2e0ba7cd3130e115c007768.tar.gz cpython-b056562860c227bad2e0ba7cd3130e115c007768.tar.bz2 |
bpo-33509: Fix _warnings for module_globals=None (#6833)
Don't crash on warnings.warn_explicit() if module_globals is not a dict.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_warnings/__init__.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py index 31ab94b..940db5c 100644 --- a/Lib/test/test_warnings/__init__.py +++ b/Lib/test/test_warnings/__init__.py @@ -218,6 +218,25 @@ class FilterTests(BaseTest): 42) self.assertEqual(len(w), 0) + def test_module_globals(self): + with original_warnings.catch_warnings(record=True, + module=self.module) as w: + # bpo-33509: module_globals=None must not crash + self.module.warn_explicit('msg', UserWarning, "filename", 42, + module_globals=None) + self.assertEqual(len(w), 1) + + # Invalid module_globals type + with self.assertRaises(TypeError): + self.module.warn_explicit('msg', UserWarning, "filename", 42, + module_globals=True) + self.assertEqual(len(w), 1) + + # Empty module_globals + self.module.warn_explicit('msg', UserWarning, "filename", 42, + module_globals={}) + self.assertEqual(len(w), 2) + def test_inheritance(self): with original_warnings.catch_warnings(module=self.module) as w: self.module.resetwarnings() |