From 18964af9d3e8ab4c45c208ff61a7a3b84be5b48e Mon Sep 17 00:00:00 2001 From: DPR Date: Fri, 17 Nov 2023 11:28:52 +0800 Subject: [PATCH 1/3] use self.assertRaises instead --- Lib/test/test_asyncio/test_streams.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py index ccb7dbf667c320..074490408c0eee 100644 --- a/Lib/test/test_asyncio/test_streams.py +++ b/Lib/test/test_asyncio/test_streams.py @@ -1122,13 +1122,10 @@ async def inner(httpd): self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx)) with test_utils.run_test_server() as httpd: - try: - self.loop.run_until_complete(inner(httpd)) # This exception is caused by `self.loop.stop()` as expected. - except RuntimeError: - pass - finally: - gc.collect() + with self.assertRaises(RuntimeError): + self.loop.run_until_complete(inner(httpd)) + gc.collect() self.assertEqual(messages, []) From 68f1f71be0cefec7be4ab4dd47e67e6498dcf625 Mon Sep 17 00:00:00 2001 From: DPR Date: Fri, 17 Nov 2023 13:00:00 +0800 Subject: [PATCH 2/3] move comment under assert --- Lib/test/test_asyncio/test_streams.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py index 074490408c0eee..fd1f8f4325a682 100644 --- a/Lib/test/test_asyncio/test_streams.py +++ b/Lib/test/test_asyncio/test_streams.py @@ -1122,8 +1122,8 @@ async def inner(httpd): self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx)) with test_utils.run_test_server() as httpd: - # This exception is caused by `self.loop.stop()` as expected. with self.assertRaises(RuntimeError): + # This exception is caused by `self.loop.stop()` as expected. self.loop.run_until_complete(inner(httpd)) gc.collect() From f3020a30e4a5359382751561fc2091f6dea498c2 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sat, 18 Nov 2023 19:05:56 -0800 Subject: [PATCH 3/3] Indent comment --- Lib/test/test_asyncio/test_streams.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py index fd1f8f4325a682..b408cd1f7da205 100644 --- a/Lib/test/test_asyncio/test_streams.py +++ b/Lib/test/test_asyncio/test_streams.py @@ -1123,7 +1123,7 @@ async def inner(httpd): with test_utils.run_test_server() as httpd: with self.assertRaises(RuntimeError): - # This exception is caused by `self.loop.stop()` as expected. + # This exception is caused by `self.loop.stop()` as expected. self.loop.run_until_complete(inner(httpd)) gc.collect()