mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-13 06:24:16 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
72ad6dc953
commit
f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions
|
|
@ -1,12 +1,14 @@
|
|||
from __future__ import annotations
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -34,22 +36,22 @@ class catch_threading_exception:
|
|||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.args: Optional["threading.ExceptHookArgs"] = None
|
||||
self._old_hook: Optional[Callable[["threading.ExceptHookArgs"], Any]] = None
|
||||
self.args: threading.ExceptHookArgs | None = None
|
||||
self._old_hook: Callable[[threading.ExceptHookArgs], Any] | None = None
|
||||
|
||||
def _hook(self, args: "threading.ExceptHookArgs") -> None:
|
||||
def _hook(self, args: threading.ExceptHookArgs) -> None:
|
||||
self.args = args
|
||||
|
||||
def __enter__(self) -> "catch_threading_exception":
|
||||
def __enter__(self) -> catch_threading_exception:
|
||||
self._old_hook = threading.excepthook
|
||||
threading.excepthook = self._hook
|
||||
return self
|
||||
|
||||
def __exit__(
|
||||
self,
|
||||
exc_type: Optional[Type[BaseException]],
|
||||
exc_val: Optional[BaseException],
|
||||
exc_tb: Optional[TracebackType],
|
||||
exc_type: type[BaseException] | None,
|
||||
exc_val: BaseException | None,
|
||||
exc_tb: TracebackType | None,
|
||||
) -> None:
|
||||
assert self._old_hook is not None
|
||||
threading.excepthook = self._old_hook
|
||||
|
|
@ -64,15 +66,15 @@ def thread_exception_runtest_hook() -> Generator[None, None, None]:
|
|||
finally:
|
||||
if cm.args:
|
||||
thread_name = (
|
||||
"<unknown>" if cm.args.thread is None else 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(
|
||||
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))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue