mirror of
https://github.com/python/cpython.git
synced 2025-08-09 19:38:42 +00:00
[3.12] gh-125514: fix bug in test_traceback utility. Specify exception types in except: clauses (GH-125516) (#125525)
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
79422bc13b
commit
26725d1756
1 changed files with 10 additions and 9 deletions
|
@ -138,7 +138,7 @@ class TracebackCases(unittest.TestCase):
|
||||||
import traceback
|
import traceback
|
||||||
try:
|
try:
|
||||||
x = 1 / 0
|
x = 1 / 0
|
||||||
except:
|
except ZeroDivisionError:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
""")
|
""")
|
||||||
try:
|
try:
|
||||||
|
@ -386,9 +386,10 @@ class PurePythonExceptionFormattingMixin:
|
||||||
def get_exception(self, callable, slice_start=0, slice_end=-1):
|
def get_exception(self, callable, slice_start=0, slice_end=-1):
|
||||||
try:
|
try:
|
||||||
callable()
|
callable()
|
||||||
self.fail("No exception thrown.")
|
except BaseException:
|
||||||
except:
|
|
||||||
return traceback.format_exc().splitlines()[slice_start:slice_end]
|
return traceback.format_exc().splitlines()[slice_start:slice_end]
|
||||||
|
else:
|
||||||
|
self.fail("No exception thrown.")
|
||||||
|
|
||||||
callable_line = get_exception.__code__.co_firstlineno + 2
|
callable_line = get_exception.__code__.co_firstlineno + 2
|
||||||
|
|
||||||
|
@ -1490,7 +1491,7 @@ class BaseExceptionReportingTests:
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
raise Exception
|
raise Exception
|
||||||
except:
|
except Exception:
|
||||||
raise ZeroDivisionError from None
|
raise ZeroDivisionError from None
|
||||||
except ZeroDivisionError as _:
|
except ZeroDivisionError as _:
|
||||||
e = _
|
e = _
|
||||||
|
@ -1838,9 +1839,9 @@ class BaseExceptionReportingTests:
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
raise EG("eg1", [ValueError(1), TypeError(2)])
|
raise EG("eg1", [ValueError(1), TypeError(2)])
|
||||||
except:
|
except EG:
|
||||||
raise EG("eg2", [ValueError(3), TypeError(4)])
|
raise EG("eg2", [ValueError(3), TypeError(4)])
|
||||||
except:
|
except EG:
|
||||||
raise ImportError(5)
|
raise ImportError(5)
|
||||||
|
|
||||||
expected = (
|
expected = (
|
||||||
|
@ -1889,7 +1890,7 @@ class BaseExceptionReportingTests:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
exc = e
|
exc = e
|
||||||
raise EG("eg", [VE(1), exc, VE(4)])
|
raise EG("eg", [VE(1), exc, VE(4)])
|
||||||
except:
|
except EG:
|
||||||
raise EG("top", [VE(5)])
|
raise EG("top", [VE(5)])
|
||||||
|
|
||||||
expected = (f' + Exception Group Traceback (most recent call last):\n'
|
expected = (f' + Exception Group Traceback (most recent call last):\n'
|
||||||
|
@ -2642,7 +2643,7 @@ class TestTracebackException(unittest.TestCase):
|
||||||
def f():
|
def f():
|
||||||
try:
|
try:
|
||||||
1/0
|
1/0
|
||||||
except:
|
except ZeroDivisionError:
|
||||||
f()
|
f()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -2731,7 +2732,7 @@ class TestTracebackException(unittest.TestCase):
|
||||||
def raise_exc():
|
def raise_exc():
|
||||||
try:
|
try:
|
||||||
raise ValueError('bad value')
|
raise ValueError('bad value')
|
||||||
except:
|
except ValueError:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def raise_with_locals():
|
def raise_with_locals():
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue