如何在pytest-aiohttp中使用fixture' test_client

时间:2017-11-17 22:10:18

标签: pytest aiohttp

有基本测试

from aiohttp import web

async def hello(request):
    return web.Response(text='Hello, world')

async def test_hello(test_client, loop):
    app = web.Application()
    app.router.add_get('/', hello)
    client = await test_client(app)
    resp = await client.get('/')
    assert resp.status == 200
    text = await resp.text()
    assert 'Hello, world' in text

fixture' test_client'找不到

  available fixtures: cache, capfd, capsys, doctest_namespace, event_loop, event_loop_process_pool, loop, monkeypatch,
     

pytestconfig,record_xml_property,recwarn,tmpdir,tmpdir_factory,unused_tcp_port,unused_tcp_port_factory

1 个答案:

答案 0 :(得分:0)

您需要安装pytest-aiohttp插件。

pip install pytest-aiohttp

在aiohttp文档中的testing chapter开头描述。