mirror of
https://github.com/python/cpython.git
synced 2025-08-01 15:43:13 +00:00
[3.13] gh-125514: fix bug in test_traceback utility. Specify exception types in except: clauses (GH-125516) (#125524)
gh-125514: fix bug in test_traceback utility. Specify exception types in except: clauses (GH-125516)
(cherry picked from commit 55c4f4c30b
)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This commit is contained in:
parent
35d9624109
commit
3b8477b81a
1 changed files with 10 additions and 9 deletions
|
@ -150,7 +150,7 @@ class TracebackCases(unittest.TestCase):
|
|||
import traceback
|
||||
try:
|
||||
x = 1 / 0
|
||||
except:
|
||||
except ZeroDivisionError:
|
||||
traceback.print_exc()
|
||||
""")
|
||||
try:
|
||||
|
@ -550,9 +550,10 @@ class PurePythonExceptionFormattingMixin:
|
|||
def get_exception(self, callable, slice_start=0, slice_end=-1):
|
||||
try:
|
||||
callable()
|
||||
self.fail("No exception thrown.")
|
||||
except:
|
||||
except BaseException:
|
||||
return traceback.format_exc().splitlines()[slice_start:slice_end]
|
||||
else:
|
||||
self.fail("No exception thrown.")
|
||||
|
||||
callable_line = get_exception.__code__.co_firstlineno + 2
|
||||
|
||||
|
@ -2234,7 +2235,7 @@ class BaseExceptionReportingTests:
|
|||
try:
|
||||
try:
|
||||
raise Exception
|
||||
except:
|
||||
except Exception:
|
||||
raise ZeroDivisionError from None
|
||||
except ZeroDivisionError as _:
|
||||
e = _
|
||||
|
@ -2586,9 +2587,9 @@ class BaseExceptionReportingTests:
|
|||
try:
|
||||
try:
|
||||
raise EG("eg1", [ValueError(1), TypeError(2)])
|
||||
except:
|
||||
except EG:
|
||||
raise EG("eg2", [ValueError(3), TypeError(4)])
|
||||
except:
|
||||
except EG:
|
||||
raise ImportError(5)
|
||||
|
||||
expected = (
|
||||
|
@ -2638,7 +2639,7 @@ class BaseExceptionReportingTests:
|
|||
except Exception as e:
|
||||
exc = e
|
||||
raise EG("eg", [VE(1), exc, VE(4)])
|
||||
except:
|
||||
except EG:
|
||||
raise EG("top", [VE(5)])
|
||||
|
||||
expected = (f' + Exception Group Traceback (most recent call last):\n'
|
||||
|
@ -3451,7 +3452,7 @@ class TestTracebackException(unittest.TestCase):
|
|||
def f():
|
||||
try:
|
||||
1/0
|
||||
except:
|
||||
except ZeroDivisionError:
|
||||
f()
|
||||
|
||||
try:
|
||||
|
@ -3555,7 +3556,7 @@ class TestTracebackException(unittest.TestCase):
|
|||
def raise_exc():
|
||||
try:
|
||||
raise ValueError('bad value')
|
||||
except:
|
||||
except ValueError:
|
||||
raise
|
||||
|
||||
def raise_with_locals():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue