Trying to import a submodule from another module and not a package was raising
AttributeError in importlib when it should be an ImportError.
Found when running importlib against test_runpy.
diff --git a/Lib/importlib/test/import_/test_packages.py b/Lib/importlib/test/import_/test_packages.py
index 1a15ebb..faadc32 100644
--- a/Lib/importlib/test/import_/test_packages.py
+++ b/Lib/importlib/test/import_/test_packages.py
@@ -21,6 +21,12 @@
with self.assertRaises(ImportError):
import_util.import_('pkg.module')
+ def test_module_not_package(self):
+ # Try to import a submodule from a non-package should raise ImportError.
+ assert not hasattr(sys, '__path__')
+ with self.assertRaises(ImportError):
+ import_util.import_('sys.no_submodules_here')
+
def test_main():
from test.support import run_unittest