Skip to content

Commit

Permalink
allow extra arguments to app_factory, line lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Jun 4, 2016
1 parent 2c7a81f commit 816c72f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions aiohttp/pytest_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import pytest

from .test_utils import TestClient, loop_context, setup_test_loop, teardown_test_loop
from .test_utils import (TestClient, loop_context, setup_test_loop,
teardown_test_loop)


@contextlib.contextmanager
Expand Down Expand Up @@ -31,9 +32,13 @@ def pytest_pyfunc_call(pyfuncitem):
Run coroutines in an event loop instead of a normal function call.
"""
if asyncio.iscoroutinefunction(pyfuncitem.function):
with _passthrough_loop_context(pyfuncitem.funcargs.get('loop')) as _loop:
testargs = {arg: pyfuncitem.funcargs[arg] for arg in pyfuncitem._fixtureinfo.argnames}
_loop.run_until_complete(_loop.create_task(pyfuncitem.obj(**testargs)))
existing_loop = pyfuncitem.funcargs.get('loop', None)
with _passthrough_loop_context(existing_loop) as _loop:
testargs = {arg: pyfuncitem.funcargs[arg]
for arg in pyfuncitem._fixtureinfo.argnames}

task = _loop.create_task(pyfuncitem.obj(**testargs))
_loop.run_until_complete(task)

return True

Expand All @@ -48,9 +53,9 @@ def loop():
def test_client(loop):
client = None

async def _create_from_app_factory(app_factory):
async def _create_from_app_factory(app_factory, *args, **kwargs):
nonlocal client
app = app_factory(loop)
app = app_factory(loop, *args, **kwargs)
client = TestClient(app)
await client.start_server()
return client
Expand Down

0 comments on commit 816c72f

Please sign in to comment.