跳转到主要内容

aiohttp支持的pytest插件

项目描述

aiohttp支持的pytest插件

该库为创建测试aiohttp服务器和客户端提供了有用的配置项。

安装

$ pip install pytest-aiohttp

asyncio_mode = auto 行添加到 pytest配置(有关详细信息,请参阅pytest-asyncio模式)。该插件也支持严格模式。

用法

使用提供的配置项以pytest-asyncio风格编写测试,用于创建aiohttp测试服务器和客户端。该插件提供了一键资源清理。

简单用法示例

from aiohttp import web


async def hello(request):
    return web.Response(body=b"Hello, world")


def create_app():
    app = web.Application()
    app.router.add_route("GET", "/", hello)
    return app


async def test_hello(aiohttp_client):
    client = await aiohttp_client(create_app())
    resp = await client.get("/")
    assert resp.status == 200
    text = await resp.text()
    assert "Hello, world" in text

有关 fixtures 使用更详细的信息,请参阅 aiohttp 文档 <https://docs.aiohttp.org/en/stable/testing.html#pytest>

项目详情


下载文件

下载适合您平台文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源分发

pytest-aiohttp-1.0.5.tar.gz (12.2 kB 查看哈希值)

上传时间

构建分发

pytest_aiohttp-1.0.5-py3-none-any.whl (8.5 kB 查看哈希值)

上传时间 Python 3

由以下提供支持

AWSAWS云计算和安全赞助商DatadogDatadog监控FastlyFastlyCDNGoogleGoogle下载分析MicrosoftMicrosoftPSF赞助商PingdomPingdom监控SentrySentry错误日志StatusPageStatusPage状态页面