Issue #29507: Update test_exceptions

test_unraisable() of test_exceptions expects that PyErr_WriteUnraisable(method)
fails on repr(method).

Before the previous change (7b8df4a5d81d), slot_tp_finalize() called
PyErr_WriteUnraisable() with a PyMethodObject. In this case, repr(method) calls
repr(self) which is BrokenRepr.__repr__() and the calls raises a new exception.

After the previous change, slot_tp_finalize() uses an unbound method: repr() is
called on a regular __del__() method which doesn't call repr(self). repr()
doesn't fail anymore.

PyErr_WriteUnraisable() doesn't call __repr__() anymore, so remove BrokenRepr
unit test.
This commit is contained in:
Victor Stinner 2017-02-09 23:49:50 +01:00
parent 516b98161a
commit 331bbe6aaa
1 changed files with 2 additions and 9 deletions

View File

@ -1023,26 +1023,19 @@ class ExceptionTests(unittest.TestCase):
# The following line is included in the traceback report: # The following line is included in the traceback report:
raise exc raise exc
class BrokenRepr(BrokenDel):
def __repr__(self):
raise AttributeError("repr() is broken")
class BrokenExceptionDel: class BrokenExceptionDel:
def __del__(self): def __del__(self):
exc = BrokenStrException() exc = BrokenStrException()
# The following line is included in the traceback report: # The following line is included in the traceback report:
raise exc raise exc
for test_class in (BrokenDel, BrokenRepr, BrokenExceptionDel): for test_class in (BrokenDel, BrokenExceptionDel):
with self.subTest(test_class): with self.subTest(test_class):
obj = test_class() obj = test_class()
with captured_stderr() as stderr: with captured_stderr() as stderr:
del obj del obj
report = stderr.getvalue() report = stderr.getvalue()
self.assertIn("Exception ignored", report) self.assertIn("Exception ignored", report)
if test_class is BrokenRepr:
self.assertIn("<object repr() failed>", report)
else:
self.assertIn(test_class.__del__.__qualname__, report) self.assertIn(test_class.__del__.__qualname__, report)
self.assertIn("test_exceptions.py", report) self.assertIn("test_exceptions.py", report)
self.assertIn("raise exc", report) self.assertIn("raise exc", report)