Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unwrapping exceptions from decorated functions #197

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/synchronicity/async_wrap.py
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ def wraps_by_interface(interface: Interface, func):

Note: Does not forward async generator information other than explicit annotations
"""
if inspect.iscoroutinefunction(func) and interface == Interface._ASYNC_WITH_BLOCKING_TYPES:
if is_coroutine_function_follow_wrapped(func) and interface == Interface._ASYNC_WITH_BLOCKING_TYPES:

def asyncfunc_deco(user_wrapper):
@functools.wraps(func)
25 changes: 25 additions & 0 deletions test/exception_test.py
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@

import asyncio
import concurrent
import functools
import inspect
import pytest
import time
@@ -164,3 +165,27 @@ async def test_function_raises_with_cause_async_syncwrap(synchronizer):
await coro
assert SLEEP_DELAY < time.monotonic() - t0 < 2 * SLEEP_DELAY
assert isinstance(exc.value.__cause__, CustomExceptionCause)


def decorator(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
return f(*args, **kwargs)

return wrapper


f_raises_wrapped = decorator(f_raises)


@pytest.mark.asyncio
async def test_wrapped_function_raises_async(synchronizer):
t0 = time.monotonic()
f_raises_s = synchronizer.create_blocking(f_raises_wrapped)
coro = f_raises_s.aio()
assert inspect.iscoroutine(coro)
assert time.monotonic() - t0 < SLEEP_DELAY
with pytest.raises(CustomException) as exc:
await coro
assert SLEEP_DELAY < time.monotonic() - t0 < 2 * SLEEP_DELAY
assert exc.value.__suppress_context__ or exc.value.__context__ is None