diff options
author | Brett Cannon <brett@python.org> | 2015-08-11 18:01:31 -0700 |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2015-08-11 18:01:31 -0700 |
commit | f6c8d9988e5a4deaa45f6b7e6436674f0d6013e4 (patch) | |
tree | dfd3f6576b0d17b4cc564e03243a58d82260687a /Lib/test/test_import | |
parent | 402dc35d5bc07da7a5cd75775250cb30a4ff1920 (diff) | |
download | cpython-f6c8d9988e5a4deaa45f6b7e6436674f0d6013e4.tar.gz |
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/test_import')
-rw-r--r-- | Lib/test/test_import/__init__.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_import/__init__.py b/Lib/test/test_import/__init__.py index 586478ff27..14a688de1c 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): |