summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_traceback.py
diff options
context:
space:
mode:
authorSimon-Martin Schröder <martin.schroeder@nerdluecht.de>2022-07-11 09:14:15 (GMT)
committerGitHub <noreply@github.com>2022-07-11 09:14:15 (GMT)
commit46fc584b00f2ccee5b77d8fc525881def8670a02 (patch)
treed8b899911c740c27a46423686b444870cbfc1e90 /Lib/test/test_traceback.py
parentda717519ecd17bf6c7ed334c12ff861f63b0f14f (diff)
downloadcpython-46fc584b00f2ccee5b77d8fc525881def8670a02.zip
cpython-46fc584b00f2ccee5b77d8fc525881def8670a02.tar.gz
cpython-46fc584b00f2ccee5b77d8fc525881def8670a02.tar.bz2
gh-87822: Make traceback module robust to exceptions from repr() of local values (GH-94691)
Diffstat (limited to 'Lib/test/test_traceback.py')
-rw-r--r--Lib/test/test_traceback.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py
index f4161fb..602bd2c 100644
--- a/Lib/test/test_traceback.py
+++ b/Lib/test/test_traceback.py
@@ -2279,6 +2279,9 @@ class TestStack(unittest.TestCase):
f' File "{__file__}", line {lno}, in f\n 1/0\n'
)
+class Unrepresentable:
+ def __repr__(self) -> str:
+ raise Exception("Unrepresentable")
class TestTracebackException(unittest.TestCase):
@@ -2546,12 +2549,13 @@ class TestTracebackException(unittest.TestCase):
linecache.updatecache('/foo.py', globals())
e = Exception("uh oh")
c = test_code('/foo.py', 'method')
- f = test_frame(c, globals(), {'something': 1, 'other': 'string'})
+ f = test_frame(c, globals(), {'something': 1, 'other': 'string', 'unrepresentable': Unrepresentable()})
tb = test_tb(f, 6, None, 0)
exc = traceback.TracebackException(
Exception, e, tb, capture_locals=True)
self.assertEqual(
- exc.stack[0].locals, {'something': '1', 'other': "'string'"})
+ exc.stack[0].locals,
+ {'something': '1', 'other': "'string'", 'unrepresentable': '<local repr() failed>'})
def test_no_locals(self):
linecache.updatecache('/foo.py', globals())