MCPcopy Create free account
hub / github.com/pytest-dev/pytest / install_importhook

Function install_importhook

src/_pytest/assertion/__init__.py:89–102  ·  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

87
88
89def 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
105def 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