diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py --- a/Lib/test/test_import.py +++ b/Lib/test/test_import.py @@ -340,6 +340,28 @@ except ImportError: self.fail("fromlist must allow bogus names") + def test_import_error_in_from_import(self): + """ + Check that an ImportError in a module bubbles up if imported using + the `from package import module` syntax. + + """ + package_dir = TESTFN + sys.path.insert(0, os.curdir) + try: + os.mkdir(package_dir) + script_helper.make_script(package_dir, '__init__', '') + script_helper.make_script(package_dir, 'foo', + "raise ImportError('blah')") + try: + __import__(package_dir, fromlist=['foo']) + self.fail('ImportError not raised') + except ImportError as e: + self.assertEqual(str(e), 'blah') + finally: + del sys.path[0] + rmtree(package_dir) + class PycRewritingTests(unittest.TestCase): # Test that the `co_filename` attribute on code objects always points