webtest sanic提供webtest与sanic应用程序的集成
webtest-sanic的Python项目详细描述
网络测试SANIC
webtest与Sanic应用程序的集成 最初创建它是为了在Webargs模块中启用sanic支持
示例代码
importasynciofromsanicimportSanicfromsanic.responseimportjsonfromwebtest_sanicimportTestAppapp=Sanic()@app.route('/')asyncdeftest(request):returnjson({'hello':'world'})loop=asyncio.new_event_loop()deftest_hello():client=TestApp(app,loop=loop)res=client.get('/')assertres.status_code==200assertres.json=={'message':'Hello world'}
安装
从pip
pip install webtest-sanic
或来源
git clone git@github.com:EndurantDevs/webtest-sanic.git
cd webtest-sanic
python setup.py install
运行测试
要确保从源代码安装之前一切正常,请运行:
python setup.py test
或
pytest tests/
学分
此代码基于webtest-aiohttpby Steven Loria和pytest-sanicby Yun Xu 请查看NOTICE了解更多信息。