mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
bpo-36829: Add test.support.catch_unraisable_exception() (GH-13490)
* Copy test_exceptions.test_unraisable() to test_sys.UnraisableHookTest(). * Use catch_unraisable_exception() in test_coroutines, test_exceptions, test_generators.
This commit is contained in:
parent
904e34d4e6
commit
e4d300e07c
6 changed files with 108 additions and 43 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue