-
-
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
Create a TestClient object inside a unittest_run_loop decorated AioHTTPTestCase method #2505
Comments
Please provide full example which causes an error and the exception about. So far it's hard to say what's wrong. |
@kxepal this is a complete and self-contained example; if I'm creating TestClient in the wrong way please help me because I have not found a better way. #!/usr/bin/env python
# run it as:
# python -m unittest test_example.TestClientCase
from aiohttp import web
from aiohttp.test_utils import AioHTTPTestCase, unittest_run_loo
from aiohttp.test_utils import TestClient, TestServer
class TestClientCase(AioHTTPTestCase):
def _app_index(self, request):
return web.Response(body="<html><body>Here we are</body></html",
content_type='text/html')
def _app_config(self, app):
router = app.router
router.add_get('/', self._app_index)
async def get_application(self):
app = web.Application()
app.on_startup.append(self._app_config)
return app
@unittest_run_loop
async def test_using_class_attribute(self):
request = await self.client.request("GET", "/")
print(request.status)
assert request.status == 200
@unittest_run_loop
async def test_using_client(self):
tc = TestClient(
TestServer(self.app, loop=self.loop),
loop=self.loop)
request = await tc.request("GET", "/")
print(request.status)
assert request.status == 200 |
Basically you should call |
Another error: adding
|
This is correct: you should not add new routes in |
So, briefly, it is not possible to create a second TestClient object with the same functionalities of the |
Sorry, I don't follow. |
@asvetlov sorry for the waste of time, things are more complicated then I expected, I will study the codebase better and I will return later if needed. Tnx. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs. |
Long story short
I'm currently not able to create a new
TestClient
object (I need it because I must set cookies) in afunction like:
Expected behaviour
Instead to works I retrieve an error about
self._root
that has no join method (is None) at line 87 of test_utils.py file.Idea about ? There is a proper set of arguments that fix the problem ?
If there is a way I will subscribe a PR with a proper example.
The text was updated successfully, but these errors were encountered: