mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
[3.6] bpo-31642: Restore blocking "from" import by setting None in sys.modules. (GH-3834). (#3923)
(cherry picked from commit f07e2b64df
)
This commit is contained in:
parent
d13a4e5067
commit
6f059ab80a
4 changed files with 259 additions and 239 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue