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

Function collect_thread_exception

src/_pytest/threadexception.py:38–74  ·  view source on GitHub ↗
(config: Config)

Source from the content-addressed store, hash-verified

36
37
38def collect_thread_exception(config: Config) -> None:
39 pop_thread_exception = config.stash[thread_exceptions].pop
40 errors: list[pytest.PytestUnhandledThreadExceptionWarning | RuntimeError] = []
41 meta = None
42 hook_error = None
43 try:
44 while True:
45 try:
46 meta = pop_thread_exception()
47 except IndexError:
48 break
49
50 if isinstance(meta, BaseException):
51 hook_error = RuntimeError("Failed to process thread exception")
52 hook_error.__cause__ = meta
53 errors.append(hook_error)
54 continue
55
56 msg = meta.msg
57 try:
58 warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg))
59 except pytest.PytestUnhandledThreadExceptionWarning as e:
60 # This except happens when the warning is treated as an error (e.g. `-Werror`).
61 if meta.exc_value is not None:
62 # Exceptions have a better way to show the traceback, but
63 # warnings do not, so hide the traceback from the msg and
64 # set the cause so the traceback shows up in the right place.
65 e.args = (meta.cause_msg,)
66 e.__cause__ = meta.exc_value
67 errors.append(e)
68
69 if len(errors) == 1:
70 raise errors[0]
71 if errors:
72 raise ExceptionGroup("multiple thread exception warnings", errors)
73 finally:
74 del errors, meta, hook_error
75
76
77def cleanup(

Callers 4

cleanupFunction · 0.85
pytest_runtest_setupFunction · 0.85
pytest_runtest_callFunction · 0.85
pytest_runtest_teardownFunction · 0.85

Calls 2

appendMethod · 0.80
warnMethod · 0.45

Tested by

no test coverage detected