summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-09-12 06:48:27 (GMT)
committerGitHub <noreply@github.com>2017-09-12 06:48:27 (GMT)
commit9adc87b0f82e5169c5f44739f89212a86013d1c4 (patch)
tree62093b01728ee2ffad9ae8585abe8b03635ec917 /Lib/test
parentcb356c2ecc0528d47fee2b9f4b32da4fcfb48b3a (diff)
downloadcpython-9adc87b0f82e5169c5f44739f89212a86013d1c4.zip
cpython-9adc87b0f82e5169c5f44739f89212a86013d1c4.tar.gz
cpython-9adc87b0f82e5169c5f44739f89212a86013d1c4.tar.bz2
[3.6] bpo-31416: Fix assertion failures in case of a bad warnings.filters or warnings.defaultaction. (GH-3496) (#3509)
Patch by Oren Milman.. (cherry picked from commit 9d984fd2b097c8c29479d1c3eb740995fe1ccb0d)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_warnings/__init__.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py
index c66fe3a..354da6b 100644
--- a/Lib/test/test_warnings/__init__.py
+++ b/Lib/test/test_warnings/__init__.py
@@ -805,6 +805,21 @@ class _WarningsTests(BaseTest, unittest.TestCase):
with self.assertRaises(TypeError):
wmod.warn_explicit('foo', Warning, 'bar', 1, registry=None)
+ @support.cpython_only
+ def test_issue31416(self):
+ # warn_explicit() shouldn't cause an assertion failure in case of a
+ # bad warnings.filters or warnings.defaultaction.
+ wmod = self.module
+ with original_warnings.catch_warnings(module=wmod):
+ wmod.filters = [(None, None, Warning, None, 0)]
+ with self.assertRaises(TypeError):
+ wmod.warn_explicit('foo', Warning, 'bar', 1)
+
+ wmod.filters = []
+ with support.swap_attr(wmod, 'defaultaction', None), \
+ self.assertRaises(TypeError):
+ wmod.warn_explicit('foo', Warning, 'bar', 1)
+
class WarningsDisplayTests(BaseTest):