如何使用夹具“test_client在pytest-aiohttp

如何使用夹具“test_client在pytest-aiohttp

问题描述:

有一个基本测试如何使用夹具“test_client在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 

夹具 '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

+0

'test_client'既不被导入也不被定义。你期望它来自哪里?我倾向于认为你最低限度需要'导入pytest',如果它可能被插件自动添加到灯具空间。 – scanny

您需要安装0个插件。

pip install pytest-aiohttp 

在aiohttp文档中描述了testing chapter的非常开始。

+0

计算机重新启动后执行测试 –