Young87

当前位置:首页 >个人收藏

aiohttp/flask python后端单元测试,单元测试覆盖率测试

aiohttp web服务器单元测试

官方代码:https://github.com/aio-libs/aiohttp/blob/master/tests/test_client_functional.py

安装插件

pip install pytest-aiohttp

后端+测试 文件 server.py

import pytest
from aiohttp import web
import aiohttp
import logging
import datetime

routes = web.RouteTableDef()

@routes.get('/')
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



@routes.get('

除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog

上一篇: 关于CSDN"原力计划"活动说明

下一篇: LeetCode452. 用最少数量的箭引爆气球

精华推荐