MCPcopy
hub / github.com/pytest-dev/pytest / install_importhook

Function install_importhook

src/_pytest/assertion/__init__.py:129–142  ·  src/_pytest/assertion/__init__.py::install_importhook

Try to install the rewrite hook, raise SystemError if it fails.

(config: Config)

Source from the content-addressed store, hash-verified

127
128
129def install_importhook(config: Config) -> rewrite.AssertionRewritingHook:
130 class="st">""class="st">"Try to install the rewrite hook, raise SystemError if it fails."class="st">""
131 config.stash[assertstate_key] = AssertionState(config, class="st">"rewrite")
132 config.stash[assertstate_key].hook = hook = rewrite.AssertionRewritingHook(config)
133 sys.meta_path.insert(0, hook)
134 config.stash[assertstate_key].trace(class="st">"installed rewrite import hook")
135
136 def undo() -> None:
137 hook = config.stash[assertstate_key].hook
138 if hook is not None and hook in sys.meta_path:
139 sys.meta_path.remove(hook)
140
141 config.add_cleanup(undo)
142 return hook
143
144
145def pytest_collection(session: Session) -> None:

Callers

nothing calls this directly

Calls 4

AssertionStateClass · 0.85
insertMethod · 0.80
traceMethod · 0.80
add_cleanupMethod · 0.80

Tested by

no test coverage detected