当前位置: 代码迷 >> 综合 >> pytest-提取返回数据中的值
  详细解决方案

pytest-提取返回数据中的值

热度:49   发布时间:2023-12-06 07:52:40.0

编写一个例子respose 就是请求的返回数据

    respose = {"errcode": 0,"errmsg": "处理成功","data": {"list": [{"tcode": "","configTemplateId": 14410001,"pageAdjuster": "1"}],"total": 1,"totalPage": 1,"pageNum": 1,"pageSize": 20},"globalTicket": "25-4678668120","monitorTrackId": null
}

json格式提取

configTemplateId = respose.json()['data']['list'][0]['configTemplateId']

jsonpath提取

import jsonpath
configTemplateId = jsonpath.jsonpath(respose.json(),'$.data.list[0].configTemplateId')

参考文章:
https://cloud.tencent.com/developer/article/1784137