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

Function register_assert_rewrite

src/_pytest/assertion/__init__.py:84–106  ·  view source on GitHub ↗

Register one or more module names to be rewritten on import. This function will make sure that this module or all modules inside the package will get their assert statements rewritten. Thus you should make sure to call this before the module is actually imported, usually in your __i

(*names: str)

Source from the content-addressed store, hash-verified

82
83
84def register_assert_rewrite(*names: str) -> None:
85 """Register one or more module names to be rewritten on import.
86
87 This function will make sure that this module or all modules inside
88 the package will get their assert statements rewritten.
89 Thus you should make sure to call this before the module is
90 actually imported, usually in your __init__.py if you are a plugin
91 using a package.
92
93 :param names: The module names to register.
94 """
95 for name in names:
96 if not isinstance(name, str):
97 msg = "expected module names as *args, got {0} instead" # type: ignore[unreachable]
98 raise TypeError(msg.format(repr(names)))
99 rewrite_hook: RewriteHook
100 for hook in sys.meta_path:
101 if isinstance(hook, rewrite.AssertionRewritingHook):
102 rewrite_hook = hook
103 break
104 else:
105 rewrite_hook = DummyRewriteHook()
106 rewrite_hook.mark_rewrite(*names)
107
108
109class RewriteHook(Protocol):

Callers

nothing calls this directly

Calls 3

mark_rewriteMethod · 0.95
DummyRewriteHookClass · 0.85
formatMethod · 0.45

Tested by

no test coverage detected