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

Function install_importhook

src/_pytest/assertion/__init__.py:129–142  ·  view source on GitHub ↗

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 """Try to install the rewrite hook, raise SystemError if it fails."""
131 config.stash[assertstate_key] = AssertionState(config, "rewrite")
132 config.stash[assertstate_key].hook = hook = rewrite.AssertionRewritingHook(config)
133 sys.meta_path.insert(0, hook)
134 config.stash[assertstate_key].trace("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

Used in the wild real call sites across dependent graphs

searching dependent graphs…