summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2015-08-12 01:01:31 (GMT)
committerBrett Cannon <brett@python.org>2015-08-12 01:01:31 (GMT)
commit3008bc0f4abb3f71433b1fcd97cc801da0a866cc (patch)
tree2eefd4a3a25a4e0234225452541254715ada79e2 /Lib/test
parentbb8a52a8d37bd8e273eddd050f91e7d423bff3c9 (diff)
downloadcpython-3008bc0f4abb3f71433b1fcd97cc801da0a866cc.zip
cpython-3008bc0f4abb3f71433b1fcd97cc801da0a866cc.tar.gz
cpython-3008bc0f4abb3f71433b1fcd97cc801da0a866cc.tar.bz2
Issue #24492: make sure that ``from ... import ...` raises an
ImportError if __name__ is not defined on a package. Thanks to Armin Rigo for the bug report and diagnosing the cause.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_import/__init__.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py
index 586478f..14a688d 100644
--- a/Lib/test/test_import/__init__.py
+++ b/Lib/test/test_import/__init__.py
@@ -324,6 +324,19 @@ class ImportTests(unittest.TestCase):
with self.assertRaisesRegex(ImportError, "^cannot import name 'bogus'"):
from re import bogus
+ def test_from_import_AttributeError(self):
+ # Issue #24492: trying to import an attribute that raises an
+ # AttributeError should lead to an ImportError.
+ class AlwaysAttributeError:
+ def __getattr__(self, _):
+ raise AttributeError
+
+ module_name = 'test_from_import_AttributeError'
+ self.addCleanup(unload, module_name)
+ sys.modules[module_name] = AlwaysAttributeError()
+ with self.assertRaises(ImportError):
+ from test_from_import_AttributeError import does_not_exist
+
@skip_if_dont_write_bytecode
class FilePermissionTests(unittest.TestCase):