diff options
author | Brett Cannon <brett@python.org> | 2012-04-27 18:01:58 (GMT) |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2012-04-27 18:01:58 (GMT) |
commit | ce418b448f431f2e62f0517f337f5b6762f4ae45 (patch) | |
tree | ec7424354c7da9d2d19419d7619bbf1607915308 /Lib/importlib/test | |
parent | 3c6ea1c14dc7a3eb67d46f96b3acdb83586f42ae (diff) | |
download | cpython-ce418b448f431f2e62f0517f337f5b6762f4ae45.zip cpython-ce418b448f431f2e62f0517f337f5b6762f4ae45.tar.gz cpython-ce418b448f431f2e62f0517f337f5b6762f4ae45.tar.bz2 |
Issue #14605: Stop having implicit entries for sys.meta_path.
ImportWarning is raised if sys.meta_path is found to be empty.
Diffstat (limited to 'Lib/importlib/test')
-rw-r--r-- | Lib/importlib/test/import_/test_meta_path.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/importlib/test/import_/test_meta_path.py b/Lib/importlib/test/import_/test_meta_path.py index 3b130c9..2f65af9 100644 --- a/Lib/importlib/test/import_/test_meta_path.py +++ b/Lib/importlib/test/import_/test_meta_path.py @@ -1,7 +1,10 @@ from .. import util from . import util as import_util +import importlib._bootstrap +import sys from types import MethodType import unittest +import warnings class CallingOrder(unittest.TestCase): @@ -33,6 +36,21 @@ class CallingOrder(unittest.TestCase): with util.import_state(meta_path=[first, second]): self.assertEqual(import_util.import_(mod_name), 42) + def test_empty(self): + # Raise an ImportWarning if sys.meta_path is empty. + module_name = 'nothing' + try: + del sys.modules[module_name] + except KeyError: + pass + with util.import_state(meta_path=[]): + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter('always') + self.assertIsNone(importlib._bootstrap._find_module('nothing', + None)) + self.assertEqual(len(w), 1) + self.assertTrue(issubclass(w[-1].category, ImportWarning)) + class CallSignature(unittest.TestCase): |