你不能用这个词来嘲弄一个特定的地址
aiohttp.web.Application()
路由器。它希望您声明相对于应用程序根的路由,如on
an example
你提到:
class MyAppTestCase(AioHTTPTestCase):
async def get_application(self):
"""
Override the get_app method to return your application.
"""
async def hello(request):
return web.Response(text='Hello, world')
app = web.Application()
app.router.add_get('/', hello)
return app
您应该测试在中创建的应用程序
get_application
方法使用
self.client
参考并使用相对路径:
@unittest_run_loop
async def test_example(self):
resp = await self.client.request("GET", "/")
assert resp.status == 200
text = await resp.text()
assert "Hello, world" in text
或者(你可能真正想要的)使用
responses
图书馆:
@responses.activate
def test_simple():
responses.add(responses.GET, 'https://stackoverflow.com',
body='Hello', status=200)