Skip to content

Commit

Permalink
Fix missing app.loop in startup hook during test (aio-libs#2068)
Browse files Browse the repository at this point in the history
  • Loading branch information
cecton authored and asvetlov committed Jul 10, 2017
1 parent 66649b0 commit 81357fd
Show file tree
Hide file tree
Showing 3 changed files with 23 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
21 changes: 21 additions & 0 deletions tests/test_loop.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 81357fd

Please sign in to comment.