小编lan*_*pta的帖子

异步和等待方法的Python pytest案例

我正在尝试为以下异步编写pytest,等待方法,但我无处可去.

   class UserDb(object):
    async def add_user_info(self,userInfo):
      return await self.post_route(route='users',json=userInfo)

    async def post_route(self,route=None,json=None,params=None):
      uri = self.uri + route if route else self.uri      
      async with self.client.post(uri,json=json,params=params) as resp:            
      assert resp.status == 200
      return await resp.json()
Run Code Online (Sandbox Code Playgroud)

有人可以帮我弄这个吗?TIA

python pytest python-3.x async-await aiohttp

7
推荐指数
1
解决办法
1195
查看次数

python pytest用于测试请求和响应

我是初学者在python中使用pytest并尝试为以下方法编写测试用例,当正确的Id传递时获取用户地址,否则上升自定义错误BadId.

    def get_user_info(id: str, host='127.0.0.1', port=3000 ) -> str:
     uri = 'http://{}:{}/users/{}'.format(host,port,id)
     result = Requests.get(uri).json()
     address = result.get('user',{}).get('address',None)
     if address:
       return address
     else:
       raise BadId
Run Code Online (Sandbox Code Playgroud)

有人可以帮我解决这个问题,你也可以建议我学习pytest的最佳资源是什么?TIA

python tdd pytest python-3.x

6
推荐指数
1
解决办法
5274
查看次数

标签 统计

pytest ×2

python ×2

python-3.x ×2

aiohttp ×1

async-await ×1

tdd ×1