diff options
| author | Victor Stinner <vstinner@redhat.com> | 2019-05-22 21:44:02 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-22 21:44:02 (GMT) |
| commit | e4d300e07c33a9a77549c62d8687d8fe130c53d5 (patch) | |
| tree | 165c92b9c1ff6f78bbffbcb4c7d68979091fc061 /Lib/test/test_generators.py | |
| parent | 904e34d4e6b6007986dcc585d5c553ee8ae06f95 (diff) | |
| download | cpython-e4d300e07c33a9a77549c62d8687d8fe130c53d5.zip cpython-e4d300e07c33a9a77549c62d8687d8fe130c53d5.tar.gz cpython-e4d300e07c33a9a77549c62d8687d8fe130c53d5.tar.bz2 | |
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.
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 |
