Skip to content

Commit

Permalink
Fix missing app.loop in startup hook during test
Browse files Browse the repository at this point in the history
  • Loading branch information
cecton committed Jul 7, 2017
1 parent c02e119 commit 04452ad
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions changes/2060.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix missing app.loop on startup hooks during tests
20 changes: 20 additions & 0 deletions tests/test_loop.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 04452ad

Please sign in to comment.