跳转到主要内容

webtest-asgi提供WebTest与ASGI应用程序的集成

项目描述

pypi badge travis-ci status Code style: Black

webtest-asgi提供WebTestASGI应用程序的集成。

免责声明

您可能应该使用Starlette的TestClient而不是此包来测试ASGI应用程序。此包是为了使用webargs的CommonTestCase测试webargs-starlette而创建的,它使用WebTest测试多个Web框架中的公共功能。

安装

pip install webtest-asgi

用法

您可以使用webtest-asgi与任何ASGI应用程序。以下是与Starlette一起使用的示例用法。

from starlette.applications import Starlette
from starlette.responses import JSONResponse
from webtest_asgi import TestApp as WebTestApp

app = Starlette()


@app.route("/")
async def homepage(request):
    return JSONResponse({"hello": "world"})


@pytest.fixture()
def testapp():
    return WebTestApp(app)


def test_get_homepage(testapp):
    assert testapp.get("/").json == {"hello": "world"}

许可证

MIT许可。有关更多详细信息,请参阅捆绑的LICENSE文件。

项目详情


下载文件

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

源代码分发

webtest-asgi-1.1.0.tar.gz (4.6 kB 查看哈希值)

上传于 源代码

构建分发

webtest_asgi-1.1.0-py2.py3-none-any.whl (3.9 kB 查看哈希值)

上传于 Python 2 Python 3

由以下支持