summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorOren Milman <orenmn@gmail.com>2017-09-19 11:23:01 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2017-09-19 11:23:01 (GMT)
commit6db7033192cd537ca987a65971acb01206c3ba82 (patch)
treef05068e6e7e700e321cd282f577570918d9c64f6 /Lib
parent453408a50508bb6801b6724ba7c7d1c017c218b6 (diff)
downloadcpython-6db7033192cd537ca987a65971acb01206c3ba82.zip
cpython-6db7033192cd537ca987a65971acb01206c3ba82.tar.gz
cpython-6db7033192cd537ca987a65971acb01206c3ba82.tar.bz2
bpo-31492: Fix assertion failures in case of a module with a bad __name__ attribute. (#3620)
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 ddef27d..5a610ba 100644
--- a/Lib/test/test_import/__init__.py
+++ b/Lib/test/test_import/__init__.py
@@ -400,6 +400,18 @@ class ImportTests(unittest.TestCase):
self.assertEqual(str(cm.exception),
"cannot import name 'does_not_exist' from '<unknown module name>' (unknown location)")
+ @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: