summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-09-27 04:33:00 (GMT)
committerGitHub <noreply@github.com>2017-09-27 04:33:00 (GMT)
commitf0db2dfda777ad3380e7816cabe4c4240f31687f (patch)
treee0c4b32926ff2eab9ce997281840f9f70ffc6ea4 /Lib
parenta1c49f6f09150f70f063417c8d67a38e59dde7ed (diff)
downloadcpython-f0db2dfda777ad3380e7816cabe4c4240f31687f.zip
cpython-f0db2dfda777ad3380e7816cabe4c4240f31687f.tar.gz
cpython-f0db2dfda777ad3380e7816cabe4c4240f31687f.tar.bz2
[3.6] bpo-31492: Fix assertion failures in case of a module with a bad __name__ attribute. (GH-3620). (#3773)
(cherry picked from commit 6db7033192cd537ca987a65971acb01206c3ba82)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_import/__init__.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py
index e811121..b73a96f 100644
--- a/Lib/test/test_import/__init__.py
+++ b/Lib/test/test_import/__init__.py
@@ -353,6 +353,18 @@ class ImportTests(unittest.TestCase):
with self.assertRaises(ImportError):
from test_from_import_AttributeError import does_not_exist
+ @cpython_only
+ def test_issue31492(self):
+ # There shouldn't be an assertion failure in case of failing to import
+ # from a module with a bad __name__ attribute, or in case of failing
+ # to access an attribute of such a module.
+ with swap_attr(os, '__name__', None):
+ with self.assertRaises(ImportError):
+ from os import does_not_exist
+
+ with self.assertRaises(AttributeError):
+ os.does_not_exist
+
def test_concurrency(self):
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'data'))
try: