diff --git a/aiohttp/test_utils.py b/aiohttp/test_utils.py index 606f9743317..312a4557267 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..8437fb539c2 --- /dev/null +++ b/tests/test_loop.py @@ -0,0 +1,20 @@ +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