mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-45924: Fix asyncio incorrect traceback when future's exception is raised multiple times (GH-30274)
This commit is contained in:
parent
f5b76330cf
commit
86c1df1872
4 changed files with 47 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue