diff options
author | larry <larry@hastings.org> | 2015-08-12 01:59:15 (GMT) |
---|---|---|
committer | larry <larry@hastings.org> | 2015-08-12 01:59:15 (GMT) |
commit | 6707906ea5e0df1132d3cd0c77707ccc19948341 (patch) | |
tree | a2fa878b8d00a791ce17dd47296f177fc45cf825 /Lib | |
parent | cae101f5ecd8fee38a37ce8fa46c141cd8a522ef (diff) | |
parent | 3008bc0f4abb3f71433b1fcd97cc801da0a866cc (diff) | |
download | cpython-6707906ea5e0df1132d3cd0c77707ccc19948341.zip cpython-6707906ea5e0df1132d3cd0c77707ccc19948341.tar.gz cpython-6707906ea5e0df1132d3cd0c77707ccc19948341.tar.bz2 |
Merged in brettcannon/cpython350/3.5 (pull request #2)
Issue #24492: make sure that ``from ... import ...` raises an ImportError if __name__ is not defined on a package.
Diffstat (limited to 'Lib')
-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 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): |