]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44017: Update test_contextlib_async not to emit DeprecationWarn (GH-25918)
authorDong-hee Na <donghee.na@python.org>
Thu, 6 May 2021 14:10:52 +0000 (23:10 +0900)
committerGitHub <noreply@github.com>
Thu, 6 May 2021 14:10:52 +0000 (23:10 +0900)
Lib/test/test_contextlib_async.py
Lib/unittest/test/testmock/testasync.py

index 290ef05b82a801203361463480b121ac7f2d52ca..cbc82dfd8f8d07a4bced096a238349715b023daa 100644 (file)
@@ -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__
 
index e1866a3492cb5080ad45928f357c708a7ace5d02..122e6956635d579f4f41ada0562b769ae55ace48 100644 (file)
@@ -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)