Skip to content
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

correct variable name in testing docs #913

Merged
merged 2 commits into from
Jun 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions aiohttp/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,16 +326,16 @@ class TestClient:

:type app: aiohttp.web.Application

:param protocol: the aiohttp.web application passed to create_test_server
:param protocol: http or https

:type app: aiohttp.web.Application
:type protocol: str

TestClient can also be used as a contextmanager, returning
the instance of itself instantiated.
"""

def __init__(self, app, protocol="http"):
self._app = app
self.app = app
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you covert app to public name?

Copy link
Member Author

@samuelcolvin samuelcolvin Jun 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, was about to make a comment about this.

Very often in tests it's helpful to get access to the app eg. to get the db connection and check data has changed as expected.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since aiohttp encourages app holding all variables this is basically the test client's only way of getting access to serverside data.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

self._loop = loop = app.loop
self.port = unused_port()
self._handler = handler = app.make_handler()
Expand Down Expand Up @@ -418,7 +418,7 @@ def close(self):
loop = self._loop
loop.run_until_complete(self._session.close())
loop.run_until_complete(self._handler.finish_connections())
loop.run_until_complete(self._app.finish())
loop.run_until_complete(self.app.finish())
self._server.close()
loop.run_until_complete(self._server.wait_closed())
self._closed = True
Expand Down
8 changes: 4 additions & 4 deletions docs/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,21 @@ Pytest example
A pytest example could look like::

# assuming you are using pytest-asyncio
from asyncio.test_utils import TestClient, loop_context
from aiohttp.test_utils import TestClient, loop_context

@pytest.yield_fixture
def loop():
with loop_context() as loop:
yield loop

@pytest.fixture
def app(test_loop):
return create_app(event_loop)
def app(loop):
return create_app(loop)


@pytest.yield_fixture
def test_client(app):
server = TestClient(app)
client = TestClient(app)
yield client
client.close()

Expand Down