summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_warnings
diff options
context:
space:
mode:
authorOren Milman <orenmn@gmail.com>2017-09-24 18:28:42 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-09-24 18:28:42 (GMT)
commit5d3e80021ab33360191eb0fbff34e0246c913884 (patch)
tree0dffddad98a53919973af779ec935c8cb449a4d9 /Lib/test/test_warnings
parent91fb0afe181986b48abfc6092dcca912b39de51d (diff)
downloadcpython-5d3e80021ab33360191eb0fbff34e0246c913884.zip
cpython-5d3e80021ab33360191eb0fbff34e0246c913884.tar.gz
cpython-5d3e80021ab33360191eb0fbff34e0246c913884.tar.bz2
bpo-31566: Fix an assertion failure in _warnings.warn() in case of a bad __name__ global. (#3717)
Diffstat (limited to 'Lib/test/test_warnings')
-rw-r--r--Lib/test/test_warnings/__init__.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py
index f27ee6e..e007dc7 100644
--- a/Lib/test/test_warnings/__init__.py
+++ b/Lib/test/test_warnings/__init__.py
@@ -856,6 +856,16 @@ class _WarningsTests(BaseTest, unittest.TestCase):
self.assertRaises(TypeError):
wmod.warn_explicit('foo', Warning, 'bar', 1)
+ @support.cpython_only
+ def test_issue31566(self):
+ # warn() shouldn't cause an assertion failure in case of a bad
+ # __name__ global.
+ with original_warnings.catch_warnings(module=self.module):
+ self.module.filterwarnings('error', category=UserWarning)
+ with support.swap_item(globals(), '__name__', b'foo'), \
+ support.swap_item(globals(), '__file__', None):
+ self.assertRaises(UserWarning, self.module.warn, 'bar')
+
class WarningsDisplayTests(BaseTest):