diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-10-08 07:44:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-08 07:44:10 (GMT) |
commit | f07e2b64df6304a36fb5e29397d3c77a7ba17704 (patch) | |
tree | ab3e39e6fd0354efc337ed87c068346b16a3f8f9 /Lib/test | |
parent | 73ffd3f2036179ed54591ef0455e5ba5694ae5bd (diff) | |
download | cpython-f07e2b64df6304a36fb5e29397d3c77a7ba17704.zip cpython-f07e2b64df6304a36fb5e29397d3c77a7ba17704.tar.gz cpython-f07e2b64df6304a36fb5e29397d3c77a7ba17704.tar.bz2 |
bpo-31642: Restore blocking "from" import by setting None in sys.modules. (#3834)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_importlib/import_/test_api.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_importlib/import_/test_api.py b/Lib/test/test_importlib/import_/test_api.py index a7bf274..0cd9de4 100644 --- a/Lib/test/test_importlib/import_/test_api.py +++ b/Lib/test/test_importlib/import_/test_api.py @@ -82,6 +82,20 @@ class APITest: self.__import__(PKG_NAME, fromlist=[SUBMOD_NAME.rpartition('.')[-1]]) + def test_blocked_fromlist(self): + # If fromlist entry is None, let a ModuleNotFoundError propagate. + # issue31642 + mod = types.ModuleType(PKG_NAME) + mod.__path__ = [] + with util.import_state(meta_path=[self.bad_finder_loader]): + with util.uncache(PKG_NAME, SUBMOD_NAME): + sys.modules[PKG_NAME] = mod + sys.modules[SUBMOD_NAME] = None + with self.assertRaises(ModuleNotFoundError) as cm: + self.__import__(PKG_NAME, + fromlist=[SUBMOD_NAME.rpartition('.')[-1]]) + self.assertEqual(cm.exception.name, SUBMOD_NAME) + class OldAPITests(APITest): bad_finder_loader = BadLoaderFinder |