bpo-44017: Update test_contextlib_async not to emit DeprecationWarn (GH-25918)

This commit is contained in:
Dong-hee Na 2021-05-06 23:10:52 +09:00 committed by GitHub
parent 985ac01637
commit 698e9a8211
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 9 deletions

View file

@ -369,16 +369,14 @@ class TestAsyncExitStack(TestBaseExitStack, unittest.TestCase):
class SyncAsyncExitStack(AsyncExitStack): class SyncAsyncExitStack(AsyncExitStack):
@staticmethod @staticmethod
def run_coroutine(coro): def run_coroutine(coro):
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop_policy().get_event_loop()
t = loop.create_task(coro)
f = asyncio.ensure_future(coro) t.add_done_callback(lambda f: loop.stop())
f.add_done_callback(lambda f: loop.stop())
loop.run_forever() loop.run_forever()
exc = f.exception() exc = t.exception()
if not exc: if not exc:
return f.result() return t.result()
else: else:
context = exc.__context__ context = exc.__context__

View file

@ -173,8 +173,7 @@ class AsyncMockTest(unittest.TestCase):
def test_future_isfuture(self): def test_future_isfuture(self):
loop = asyncio.new_event_loop() loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop) fut = loop.create_future()
fut = asyncio.Future()
loop.stop() loop.stop()
loop.close() loop.close()
mock = AsyncMock(fut) mock = AsyncMock(fut)