diff options
Diffstat (limited to 'Lib/test/test_generators.py')
-rw-r--r-- | Lib/test/test_generators.py | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index 320793c..7f1472f 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -2156,25 +2156,21 @@ explicitly, without generators. We do have to redirect stderr to avoid printing warnings and to doublecheck that we actually tested what we wanted to test. ->>> import sys, io ->>> old = sys.stderr ->>> try: -... sys.stderr = io.StringIO() -... class Leaker: -... def __del__(self): -... def invoke(message): -... raise RuntimeError(message) -... invoke("test") +>>> from test import support +>>> class Leaker: +... def __del__(self): +... def invoke(message): +... raise RuntimeError(message) +... invoke("del failed") ... +>>> with support.catch_unraisable_exception() as cm: ... l = Leaker() ... del l -... err = sys.stderr.getvalue().strip() -... "Exception ignored in" in err -... "RuntimeError: test" in err -... "Traceback" in err -... "in invoke" in err -... finally: -... sys.stderr = old +... +... cm.unraisable.object == Leaker.__del__ +... cm.unraisable.exc_type == RuntimeError +... str(cm.unraisable.exc_value) == "del failed" +... cm.unraisable.exc_traceback is not None True True True |