From 19d8c96aea383b7856e46cd285e52428a56a207b Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Thu, 16 Jun 2022 11:07:28 +0100 Subject: [PATCH] set the global event loop in _setupAsyncioRunner --- aiohttp/test_utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/aiohttp/test_utils.py b/aiohttp/test_utils.py index 82956986b9d..510e35e363d 100644 --- a/aiohttp/test_utils.py +++ b/aiohttp/test_utils.py @@ -412,6 +412,15 @@ class AioHTTPTestCase(TestCase): Note that the TestClient's methods are asynchronous: you have to execute function on the test client using asynchronous methods. """ + def _setupAsyncioRunner(self): + super()._setupAsyncioRunner() + asyncio.set_event_loop(self._asyncioRunner.get_loop()) + + def _tearDownAsyncioRunner(self): + try: + super()._tearDownAsyncioRunner() + finally: + asyncio.set_event_loop(None) async def get_application(self) -> Application: """Get application.