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)
| 82 | |
| 83 | |
| 84 | def 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 | |
| 109 | class RewriteHook(Protocol): |
nothing calls this directly
no test coverage detected