diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2017-09-24 20:14:41 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-09-24 20:14:41 (GMT) |
commit | 415cc1fa57710614ed3384d0cafc58ccf7adee8c (patch) | |
tree | b460136b8b15d4deec84f82cc232caa1d5694d31 /Lib | |
parent | ce418bf8228c9a6a19702638e5f5c2fb66ad0588 (diff) | |
download | cpython-415cc1fa57710614ed3384d0cafc58ccf7adee8c.zip cpython-415cc1fa57710614ed3384d0cafc58ccf7adee8c.tar.gz cpython-415cc1fa57710614ed3384d0cafc58ccf7adee8c.tar.bz2 |
[3.6] bpo-31566: Fix an assertion failure in _warnings.warn() in case of a bad __name__ global. (GH-3717) (#3730)
(cherry picked from commit 5d3e80021ab33360191eb0fbff34e0246c913884)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_warnings/__init__.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_warnings/__init__.py b/Lib/test/test_warnings/__init__.py index 354da6b..a07886c 100644 --- a/Lib/test/test_warnings/__init__.py +++ b/Lib/test/test_warnings/__init__.py @@ -820,6 +820,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): |