pytest 接口测试

pytest 是什么

.py文件名 用 test_开头,函数用 test_开头,运行的时候,pycharm会自动用pytest模式去执行代码!

处理excel 文件

点击获取excel 文件

核心思想: 把excel 文件的内容转化为 python的字典数组

可以先阅读 python函数 函数

注意: 需要xToolkit 只能读取 xls

puppet 复制代码
from xToolkit import xfile

test_res = xfile.read('test.xls').excel_to_dict('Sheet1')
print(test_res)
print(test_res[0]['接口URL'])

for data in test_res:
    print(data['接口URL'])

使用pytest 自动循环执行

puppet 复制代码
import  requests
from xToolkit import xfile
import pytest

# 读取excel 文件,生成字典数组
test_res = xfile.read('test.xls').excel_to_dict('Sheet1')
print(test_res)
# print(test_res[0]['接口URL'])
#
# for data in test_res:
#     print(data['接口URL'])


# 自动循环执行; data:传递的参数,test_res: 需要解析的列表
@pytest.mark.parametrize('data', test_res)
def test_excute(data):
    res = requests.request(method=data['请求方式'],
                           url=data['接口URL'])
    print(res.url)

if __name__ == '__main__':
    pytest.main(['-s', 'test2.py'])
    pytest.main(["-vs"])
相关推荐
阿pin3 小时前
Android随笔-kotlin withContext
android·kotlin·withcontext
树码小子4 小时前
开启 IDEA 中的断言功能
android·java·intellij-idea
Android-Flutter5 小时前
android 动画详解
android·kotlin
小孔龙10 小时前
GraphicBuffer 跨进程共享
android
行业研究员11 小时前
Android内置GPS与腾讯地图定位技术对比分析
android·android定位·腾讯地图定位
St_rive11 小时前
Pytest skip&&skipif跳过⽤例
运维·服务器·pytest
Android-Flutter11 小时前
android WMS 详解(二)
android·kotlin
游戏开发爱好者812 小时前
App Store 上传 IPA 自动化,.p8 密钥认证与 CI/CD 接入实战
android·运维·ci/cd·小程序·uni-app·自动化·iphone
游戏开发爱好者813 小时前
iOS 推送怎么配置,APNs 推送证书、设备库与群发
android·ios·小程序·https·uni-app·iphone·webview
阿pin14 小时前
Android随笔-kotlin 高阶函数
android·kotlin·高阶函数