From e5b25df16d10f6e3fb5010c29bfcc155f8b09bef Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Wed, 12 Jun 2013 23:38:50 -0400 Subject: [PATCH] Issue #15767: Add an explicit test for raising ModuleNotFoundError when None in sys.modules. --- Lib/test/test_importlib/import_/test_api.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Lib/test/test_importlib/import_/test_api.py b/Lib/test/test_importlib/import_/test_api.py index 6aca6dcf7d0..4b7baadab65 100644 --- a/Lib/test/test_importlib/import_/test_api.py +++ b/Lib/test/test_importlib/import_/test_api.py @@ -26,6 +26,13 @@ class APITest(unittest.TestCase): with self.assertRaises(ModuleNotFoundError): util.import_('some module that does not exist') + def test_raises_ModuleNotFoundError_for_None(self): + # None in sys.modules should raise ModuleNotFoundError. + with importlib_test_util.uncache('not_here'): + sys.modules['not_here'] = None + with self.assertRaises(ModuleNotFoundError): + util.import_('not_here') + def test_name_requires_rparition(self): # Raise TypeError if a non-string is passed in for the module name. with self.assertRaises(TypeError):