-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test_client should accept application object as parameter #1066
Comments
Good idea. |
This can be easily achieved without changes to library: def test_something(test_client):
client = await test_client(lambda loop: app) However allowing to pass application object instead of factory can lead to unexpected and |
@popravich but people will either create app in test method or use a fixture for it. |
Should I remind you several discussions with word "global" (remember aiopg global pool, recent aiohttp "how to get global app", etc)? Anyway, having this feature must require big red warning block in docs saying not to use global app |
I can live with a big red warning but really need the functionality.
with
I've found the second snipped is more straightforward. Moving |
...and with async def test_2(test_client): # missing loop fixture
async def handler(request):
...
app = web.Application(loop=loop)
app.router.add_get('/', handler)
client = test_client(lambda loop: app) Just 13 chars more and nothing to change in aiohttp Ok, if you are sure it will work. |
Jut a simple thought: if |
It at least verbose that application factory will receive |
Perfect! I love this. |
Fixed by #1083 |
Long story short
This is not an issue, but a feature improvement request. Per this documentation http://aiohttp.readthedocs.io/en/stable/testing.html test_client accepts a create_app function in it's constructor. It will be cool if test_client accepts application object instead.
This feature improvement is not critical. application object is used by any wsgi server to run a service. similarly this test_client should use an application object to create server/client. It's just more convenient to think and use.
Expected behaviour
instead of
@pytest.fixture
def cli(loop, test_client):
return loop.run_until_complete(test_client(create_app))
if test_client accepts app then
@pytest.fixture
def cli(loop, test_client):
return loop.run_until_complete(test_client(app))
Actual behaviour
Behavior wise nothing changes, it's just the implementation change.
Steps to reproduce
Your environment
The text was updated successfully, but these errors were encountered: