diff options
| author | robot-piglet <[email protected]> | 2025-05-05 12:31:52 +0300 |
|---|---|---|
| committer | robot-piglet <[email protected]> | 2025-05-05 12:41:33 +0300 |
| commit | 6ff49ec58061f642c3a2f83c61eba12820787dfc (patch) | |
| tree | c733ec9bdb15ed280080d31dea8725bfec717acd /contrib/python/pytest/py3/_pytest/threadexception.py | |
| parent | eefca8305c6a545cc6b16dca3eb0d91dcef2adcd (diff) | |
Intermediate changes
commit_hash:8b3bb826b17db8329ed1221f545c0645f12c552d
Diffstat (limited to 'contrib/python/pytest/py3/_pytest/threadexception.py')
| -rw-r--r-- | contrib/python/pytest/py3/_pytest/threadexception.py | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/contrib/python/pytest/py3/_pytest/threadexception.py b/contrib/python/pytest/py3/_pytest/threadexception.py index 43341e739a0..09faf661b91 100644 --- a/contrib/python/pytest/py3/_pytest/threadexception.py +++ b/contrib/python/pytest/py3/_pytest/threadexception.py @@ -1,12 +1,12 @@ import threading import traceback -import warnings from types import TracebackType from typing import Any from typing import Callable from typing import Generator from typing import Optional from typing import Type +import warnings import pytest @@ -59,30 +59,34 @@ class catch_threading_exception: def thread_exception_runtest_hook() -> Generator[None, None, None]: with catch_threading_exception() as cm: - yield - if cm.args: - thread_name = "<unknown>" if cm.args.thread is None else cm.args.thread.name - msg = f"Exception in thread {thread_name}\n\n" - msg += "".join( - traceback.format_exception( - cm.args.exc_type, - cm.args.exc_value, - cm.args.exc_traceback, + try: + yield + finally: + if cm.args: + thread_name = ( + "<unknown>" if cm.args.thread is None else cm.args.thread.name + ) + msg = f"Exception in thread {thread_name}\n\n" + msg += "".join( + traceback.format_exception( + cm.args.exc_type, + cm.args.exc_value, + cm.args.exc_traceback, + ) ) - ) - warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) + warnings.warn(pytest.PytestUnhandledThreadExceptionWarning(msg)) [email protected](hookwrapper=True, trylast=True) [email protected](wrapper=True, trylast=True) def pytest_runtest_setup() -> Generator[None, None, None]: yield from thread_exception_runtest_hook() [email protected](hookwrapper=True, tryfirst=True) [email protected](wrapper=True, tryfirst=True) def pytest_runtest_call() -> Generator[None, None, None]: yield from thread_exception_runtest_hook() [email protected](hookwrapper=True, tryfirst=True) [email protected](wrapper=True, tryfirst=True) def pytest_runtest_teardown() -> Generator[None, None, None]: yield from thread_exception_runtest_hook() |
