From e4aabd0b805ba871c91acf3dd8815dc2f3c85d92 Mon Sep 17 00:00:00 2001 From: Pavel Perestoronin Date: Fri, 4 Oct 2024 13:09:46 +0200 Subject: [PATCH] =?UTF-8?q?FIX:=20do=20not=20wrap=20`CancelledError`=20int?= =?UTF-8?q?o=20`BackendError`=20=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- combadge/core/errors.py | 2 +- tests/core/test_errors.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/core/test_errors.py diff --git a/combadge/core/errors.py b/combadge/core/errors.py index 7ca48ae..f065554 100644 --- a/combadge/core/errors.py +++ b/combadge/core/errors.py @@ -21,7 +21,7 @@ def __exit__( # type: ignore[misc] /, ) -> None: # Wrapping `CancelledError` breaks `asyncio.TaskGroup`. - if exc_value is not None and not isinstance(exc_type, CancelledError): + if exc_value is not None and not isinstance(exc_value, CancelledError): raise cls(exc_value) from exc_value diff --git a/tests/core/test_errors.py b/tests/core/test_errors.py new file mode 100644 index 0000000..82ed053 --- /dev/null +++ b/tests/core/test_errors.py @@ -0,0 +1,17 @@ +from asyncio import CancelledError + +import pytest + +from combadge.core.errors import BackendError + + +@pytest.mark.parametrize("inner_exception", [ValueError(42)]) +def test_wrapped(inner_exception: BaseException) -> None: + with pytest.raises(BackendError), BackendError: + raise inner_exception + + +@pytest.mark.parametrize("inner_exception", [CancelledError()]) +def test_non_wrapped(inner_exception: BaseException) -> None: + with pytest.raises(type(inner_exception)), BackendError: + raise inner_exception