bpo-37069: tests use catch_unraisable_exception() (GH-13762)

Modify test_coroutines, test_cprofile, test_generators, test_raise,
test_ssl and test_yield_from to use
support.catch_unraisable_exception() rather than
support.captured_stderr().

test_thread: remove test_save_exception_state_on_error() which is now
updated. test_unraisable_exception() checks that sys.unraisablehook()
is called to handle _thread.start_new_thread() exception.

test_cprofile now rely on unittest for test discovery: replace
support.run_unittest() with unittest.main().
This commit is contained in:
Victor Stinner 2019-06-03 03:51:43 +02:00 committed by GitHub
parent 13136e83a6
commit 0025350294
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 60 additions and 69 deletions

View file

@ -2032,11 +2032,17 @@ class CoroutineTest(unittest.TestCase):
def test_fatal_coro_warning(self):
# Issue 27811
async def func(): pass
with warnings.catch_warnings(), support.captured_stderr() as stderr:
with warnings.catch_warnings(), \
support.catch_unraisable_exception() as cm:
warnings.filterwarnings("error")
func()
coro = func()
# only store repr() to avoid keeping the coroutine alive
coro_repr = repr(coro)
coro = None
support.gc_collect()
self.assertIn("was never awaited", stderr.getvalue())
self.assertIn("was never awaited", str(cm.unraisable.exc_value))
self.assertEqual(repr(cm.unraisable.object), coro_repr)
def test_for_assign_raising_stop_async_iteration(self):
class BadTarget: