From dd73d81933e31e6c493e8e215ef803fcfc29cd06 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Tue, 15 Dec 2015 21:54:04 +0000 Subject: [PATCH] Amend python_destructor_exception runtime test Suppress the message that PyErr_WriteUnraisable writes to stderr, but check that it is called by checking some of the expected message contents. The output varies slightly for different versions of Python and -builtin --- .../python_destructor_exception_runme.py | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/Examples/test-suite/python/python_destructor_exception_runme.py b/Examples/test-suite/python/python_destructor_exception_runme.py index a19b48633..f9db37a13 100644 --- a/Examples/test-suite/python/python_destructor_exception_runme.py +++ b/Examples/test-suite/python/python_destructor_exception_runme.py @@ -2,13 +2,31 @@ import python_destructor_exception from StringIO import StringIO import sys -#buffer = StringIO() -#sys.stderr = buffer - -attributeErrorOccurred = False -try: +def error_function(): python_destructor_exception.ClassWithThrowingDestructor().GetBlah() -except AttributeError, e: - attributeErrorOccurred = True -assert attributeErrorOccurred +def runtest(): + attributeErrorOccurred = False + try: + error_function() + except AttributeError, e: + attributeErrorOccurred = True + return attributeErrorOccurred + +def runtestcaller(): + stderr_saved = sys.stderr + buffer = StringIO() + attributeErrorOccurred = False + try: + # Suppress stderr while making this call to suppress the output shown by PyErr_WriteUnraisable + sys.stderr = buffer + + attributeErrorOccurred = runtest() + finally: + sys.stderr.flush() + sys.stderr = stderr_saved + + assert attributeErrorOccurred + assert buffer.getvalue().count("I am the ClassWithThrowingDestructor dtor doing bad things") >= 1 + +runtestcaller()