From 81357fd8241f753c627a526d1fc88dc352ac45d4 Mon Sep 17 00:00:00 2001 From: Cecile Tonglet Date: Mon, 10 Jul 2017 14:09:38 +0200 Subject: [PATCH] Fix missing app.loop in startup hook during test (#2068) Fixes #2060 --- aiohttp/test_utils.py | 1 + changes/2060.bugfix | 1 + tests/test_loop.py | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 changes/2060.bugfix create mode 100644 tests/test_loop.py diff --git a/aiohttp/test_utils.py b/aiohttp/test_utils.py index 8b55c1fdd50..68dbd7b8065 100644 --- a/aiohttp/test_utils.py +++ b/aiohttp/test_utils.py @@ -148,6 +148,7 @@ def __init__(self, app, *, @asyncio.coroutine def _make_factory(self, **kwargs): + self.app._set_loop(self._loop) yield from self.app.startup() self.handler = self.app.make_handler(loop=self._loop, **kwargs) return self.handler diff --git a/changes/2060.bugfix b/changes/2060.bugfix new file mode 100644 index 00000000000..4c86f8dae76 --- /dev/null +++ b/changes/2060.bugfix @@ -0,0 +1 @@ +Fix missing app.loop on startup hooks during tests diff --git a/tests/test_loop.py b/tests/test_loop.py new file mode 100644 index 00000000000..25019e2e334 --- /dev/null +++ b/tests/test_loop.py @@ -0,0 +1,21 @@ +import asyncio + +from aiohttp import web +from aiohttp.test_utils import AioHTTPTestCase, unittest_run_loop + + +class TestCase(AioHTTPTestCase): + @asyncio.coroutine + def get_application(self): + app = web.Application() + app.on_startup.append(self.on_startup_hook) + return app + + @asyncio.coroutine + def on_startup_hook(self, app): + self.startup_loop = app.loop + + @unittest_run_loop + @asyncio.coroutine + def test_on_startup_hook(self): + assert self.startup_loop is not None