gh-117459: Keep the traceback in _convert_future_exc (#117460)

This commit is contained in:
rsp4jack 2024-04-04 11:13:32 +08:00 committed by GitHub
parent b4fe02f595
commit 85843348c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 4 deletions

View file

@ -5,6 +5,7 @@ import gc
import re
import sys
import threading
import traceback
import unittest
from unittest import mock
from types import GenericAlias
@ -416,6 +417,24 @@ class BaseFutureTests:
_copy_future_state(f_cancelled, newf_cancelled)
self.assertTrue(newf_cancelled.cancelled())
try:
raise concurrent.futures.InvalidStateError
except BaseException as e:
f_exc = e
f_conexc = self._new_future(loop=self.loop)
f_conexc.set_exception(f_exc)
newf_conexc = self._new_future(loop=self.loop)
_copy_future_state(f_conexc, newf_conexc)
self.assertTrue(newf_conexc.done())
try:
newf_conexc.result()
except BaseException as e:
newf_exc = e # assertRaises context manager drops the traceback
newf_tb = ''.join(traceback.format_tb(newf_exc.__traceback__))
self.assertEqual(newf_tb.count('raise concurrent.futures.InvalidStateError'), 1)
def test_iter(self):
fut = self._new_future(loop=self.loop)