From e92e817e888e239d08cde1ca757ab4c250b13351 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Sat, 16 Jul 2016 20:44:45 +0300 Subject: [PATCH] Fix #930: suppress CancelledError when Timeout raises TimeoutError --- aiohttp/helpers.py | 2 +- tests/test_timeout.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/aiohttp/helpers.py b/aiohttp/helpers.py index 256a55882b0..d93d6c5bb21 100644 --- a/aiohttp/helpers.py +++ b/aiohttp/helpers.py @@ -561,7 +561,7 @@ def __exit__(self, exc_type, exc_val, exc_tb): if exc_type is asyncio.CancelledError and self._cancelled: self._cancel_handler = None self._task = None - raise asyncio.TimeoutError + raise asyncio.TimeoutError from None if self._timeout is not None: self._cancel_handler.cancel() self._cancel_handler = None diff --git a/tests/test_timeout.py b/tests/test_timeout.py index 7d34a24cbf6..07e13a5c5ae 100644 --- a/tests/test_timeout.py +++ b/tests/test_timeout.py @@ -165,3 +165,13 @@ def outer(): yield from task assert task.cancelled() assert task.done() + + +@pytest.mark.run_loop +def test_timeout_suppress_exception_chain(loop): + + with pytest.raises(asyncio.TimeoutError) as ctx: + with Timeout(0.01, loop=loop) as t: + yield from asyncio.sleep(10, loop=loop) + assert t._loop is loop + assert ctx.value.__suppress_context__