mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
[3.11] gh-113358: Fix rendering tracebacks with exceptions with a broken __getattr__ (GH-113359) (#114118)
This commit is contained in:
parent
a4ad7a0ac5
commit
20f7cf2c7f
4 changed files with 52 additions and 2 deletions
|
@ -1601,6 +1601,21 @@ class BaseExceptionReportingTests:
|
|||
err_msg = '<note str() failed>'
|
||||
self.assertEqual(self.get_report(e), vanilla + err_msg + '\nFinal Note\n')
|
||||
|
||||
# an exception with a broken __getattr__ raising a non expected error
|
||||
class BrokenException(Exception):
|
||||
broken = False
|
||||
def __getattr__(self, name):
|
||||
if self.broken:
|
||||
raise ValueError(f'no {name}')
|
||||
raise AttributeError(name)
|
||||
|
||||
e = BrokenException(123)
|
||||
vanilla = self.get_report(e)
|
||||
e.broken = True
|
||||
self.assertEqual(
|
||||
self.get_report(e),
|
||||
vanilla + "Ignored error getting __notes__: ValueError('no __notes__')\n")
|
||||
|
||||
def test_exception_with_multiple_notes(self):
|
||||
for e in [ValueError(42), SyntaxError('bad syntax')]:
|
||||
with self.subTest(e=e):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue