summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio/test_futures2.py
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-07-11 12:32:11 (GMT)
committerGitHub <noreply@github.com>2022-07-11 12:32:11 (GMT)
commit86c1df18727568758cc329baddc1836e45664023 (patch)
treefb1d5408dd0070b83e2df33030f38491a518634a /Lib/test/test_asyncio/test_futures2.py
parentf5b76330cfb93e1ad1a77c71dafe719f6a808cec (diff)
downloadcpython-86c1df18727568758cc329baddc1836e45664023.zip
cpython-86c1df18727568758cc329baddc1836e45664023.tar.gz
cpython-86c1df18727568758cc329baddc1836e45664023.tar.bz2
bpo-45924: Fix asyncio incorrect traceback when future's exception is raised multiple times (GH-30274)
Diffstat (limited to 'Lib/test/test_asyncio/test_futures2.py')
-rw-r--r--Lib/test/test_asyncio/test_futures2.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/Lib/test/test_asyncio/test_futures2.py b/Lib/test/test_asyncio/test_futures2.py
index 60b5885..71279b6 100644
--- a/Lib/test/test_asyncio/test_futures2.py
+++ b/Lib/test/test_asyncio/test_futures2.py
@@ -1,13 +1,42 @@
# IsolatedAsyncioTestCase based tests
import asyncio
+import traceback
import unittest
+from asyncio import tasks
def tearDownModule():
asyncio.set_event_loop_policy(None)
-class FutureTests(unittest.IsolatedAsyncioTestCase):
+class FutureTests:
+
+ async def test_future_traceback(self):
+
+ async def raise_exc():
+ raise TypeError(42)
+
+ future = self.cls(raise_exc())
+
+ for _ in range(5):
+ try:
+ await future
+ except TypeError as e:
+ tb = ''.join(traceback.format_tb(e.__traceback__))
+ self.assertEqual(tb.count("await future"), 1)
+ else:
+ self.fail('TypeError was not raised')
+
+@unittest.skipUnless(hasattr(tasks, '_CTask'),
+ 'requires the C _asyncio module')
+class CFutureTests(FutureTests, unittest.IsolatedAsyncioTestCase):
+ cls = tasks._CTask
+
+class PyFutureTests(FutureTests, unittest.IsolatedAsyncioTestCase):
+ cls = tasks._PyTask
+
+class FutureReprTests(unittest.IsolatedAsyncioTestCase):
+
async def test_recursive_repr_for_pending_tasks(self):
# The call crashes if the guard for recursive call
# in base_futures:_future_repr_info is absent