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

Function unraisable_hook

src/_pytest/unraisableexception.py:107–145  ·  src/_pytest/unraisableexception.py::unraisable_hook
(
    unraisable: sys.UnraisableHookArgs,
    /,
    *,
    append: Callable[[UnraisableMeta | BaseException], object],
)

Source from the content-addressed store, hash-verified

105
106
107def unraisable_hook(
108 unraisable: sys.UnraisableHookArgs,
109 /,
110 *,
111 append: Callable[[UnraisableMeta | BaseException], object],
112) -> None:
113 try:
114 class="cm"># we need to compute these strings here as they might change after
115 class="cm"># the unraisablehook finishes and before the metadata object is
116 class="cm"># collected by a pytest hook
117 err_msg = (
118 class="st">"Exception ignored in" if unraisable.err_msg is None else unraisable.err_msg
119 )
120 summary = fclass="st">"{err_msg}: {unraisable.object!r}"
121 traceback_message = class="st">"\n\n" + class="st">"".join(
122 traceback.format_exception(
123 unraisable.exc_type,
124 unraisable.exc_value,
125 unraisable.exc_traceback,
126 )
127 )
128 tracemalloc_tb = class="st">"\n" + tracemalloc_message(unraisable.object)
129 msg = summary + traceback_message + tracemalloc_tb
130 cause_msg = summary + tracemalloc_tb
131
132 append(
133 UnraisableMeta(
134 msg=msg,
135 cause_msg=cause_msg,
136 exc_value=unraisable.exc_value,
137 )
138 )
139 except BaseException as e:
140 append(e)
141 class="cm"># Raising this will cause the exception to be logged twice, once in our
142 class="cm"># collect_unraisable and once by the unraisablehook calling machinery
143 class="cm"># which is fine - this should never happen anyway and if it does
144 class="cm"># it should probably be reported as a pytest bug.
145 raise
146
147
148def pytest_configure(config: Config) -> None:

Callers

nothing calls this directly

Calls 3

tracemalloc_messageFunction · 0.90
UnraisableMetaClass · 0.85
joinMethod · 0.80

Tested by

no test coverage detected