def test_path_hook_installed(self): # PathFinder can only use it with sys.executable on sys.path with patch('sys.path', sys.path): sys.path = [p for p in sys.path if p != sys.executable] PathFinder.invalidate_caches() self.assertIsNone(PathFinder.find_spec("pwd")) sys.path.append(sys.executable) spec = PathFinder.find_spec("pwd") self.assert_spec(spec, "pwd", is_pkg=False, Loader=sys.__spec__.loader, origin="built-in")
def invalidate_caches(cls): PathFinder.invalidate_caches()
finder2 xxx hook1 C:\Python36\lib\site-packages\win32\lib hook2 C:\Python36\lib\site-packages\win32\lib finder2 xxx hook1 C:\Python36\lib\site-packages\Pythonwin hook2 C:\Python36\lib\site-packages\Pythonwin finder2 xxx hook1 E:\my_data\program_source\python3_src\nn_ns\try_python\try_keywords hook2 E:\my_data\program_source\python3_src\nn_ns\try_python\try_keywords finder2 xxx Traceback (most recent call last): File "C:\Python36\lib\runpy.py", line 193, in _run_module_as_main ''' from importlib.machinery import PathFinder PathFinder.invalidate_caches() sys.meta_path[0:2] = [] import xxx from sys import path_hooks, path_importer_cache, modules, meta_path import sys PathFinder.invalidate_caches() path_hooks.clear() print(path_hooks) sys.path_hooks.insert(0, hook1) # insert useless?? print(sys.path_hooks) print(__import__) print(meta_path) #meta_path.pop() del meta_path[0:2] print(meta_path)