Try to install the rewrite hook, raise SystemError if it fails.
(config: Config)
| 87 | |
| 88 | |
| 89 | def install_importhook(config: Config) -> rewrite.AssertionRewritingHook: |
| 90 | """Try to install the rewrite hook, raise SystemError if it fails.""" |
| 91 | config.stash[assertstate_key] = AssertionState(config, "rewrite") |
| 92 | config.stash[assertstate_key].hook = hook = rewrite.AssertionRewritingHook(config) |
| 93 | sys.meta_path.insert(0, hook) |
| 94 | config.stash[assertstate_key].trace("installed rewrite import hook") |
| 95 | |
| 96 | def undo() -> None: |
| 97 | hook = config.stash[assertstate_key].hook |
| 98 | if hook is not None and hook in sys.meta_path: |
| 99 | sys.meta_path.remove(hook) |
| 100 | |
| 101 | config.add_cleanup(undo) |
| 102 | return hook |
| 103 | |
| 104 | |
| 105 | def pytest_collection(session: "Session") -> None: |
nothing calls this directly
no test coverage detected