| 3232 | return None |
| 3233 | |
| 3234 | class TestHook: |
| 3235 | |
| 3236 | def __init__(self, pathdir): |
| 3237 | self.sys_path = sys.path[:] |
| 3238 | self.meta_path = sys.meta_path[:] |
| 3239 | self.path_hooks = sys.path_hooks[:] |
| 3240 | sys.path.append(pathdir) |
| 3241 | sys.path_importer_cache.clear() |
| 3242 | self.modules_before = sys.modules.copy() |
| 3243 | self.importer = TestImporter() |
| 3244 | sys.meta_path.append(self.importer) |
| 3245 | |
| 3246 | def remove(self): |
| 3247 | sys.path[:] = self.sys_path |
| 3248 | sys.meta_path[:] = self.meta_path |
| 3249 | sys.path_hooks[:] = self.path_hooks |
| 3250 | sys.path_importer_cache.clear() |
| 3251 | sys.modules.clear() |
| 3252 | sys.modules.update(self.modules_before) |
| 3253 | |
| 3254 | |
| 3255 | @contextlib.contextmanager |