From 698e9a8211c46ed5dc93e5cd7026ea05dec2f373 Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 6 May 2021 23:10:52 +0900 Subject: bpo-44017: Update test_contextlib_async not to emit DeprecationWarn (GH-25918) --- Lib/test/test_contextlib_async.py | 12 +++++------- Lib/unittest/test/testmock/testasync.py | 3 +-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Lib/test/test_contextlib_async.py b/Lib/test/test_contextlib_async.py index 290ef05..cbc82df 100644 --- a/Lib/test/test_contextlib_async.py +++ b/Lib/test/test_contextlib_async.py @@ -369,16 +369,14 @@ class TestAsyncExitStack(TestBaseExitStack, unittest.TestCase): class SyncAsyncExitStack(AsyncExitStack): @staticmethod def run_coroutine(coro): - loop = asyncio.get_event_loop() - - f = asyncio.ensure_future(coro) - f.add_done_callback(lambda f: loop.stop()) + loop = asyncio.get_event_loop_policy().get_event_loop() + t = loop.create_task(coro) + t.add_done_callback(lambda f: loop.stop()) loop.run_forever() - exc = f.exception() - + exc = t.exception() if not exc: - return f.result() + return t.result() else: context = exc.__context__ diff --git a/Lib/unittest/test/testmock/testasync.py b/Lib/unittest/test/testmock/testasync.py index e1866a3..122e695 100644 --- a/Lib/unittest/test/testmock/testasync.py +++ b/Lib/unittest/test/testmock/testasync.py @@ -173,8 +173,7 @@ class AsyncMockTest(unittest.TestCase): def test_future_isfuture(self): loop = asyncio.new_event_loop() - asyncio.set_event_loop(loop) - fut = asyncio.Future() + fut = loop.create_future() loop.stop() loop.close() mock = AsyncMock(fut) -- cgit v0.12