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"])
相关推荐
2601_949543018 小时前
Flutter for OpenHarmony垃圾分类指南App实战:主题配置实现
android·flutter
2601_949833399 小时前
flutter_for_openharmony口腔护理app实战+知识实现
android·javascript·flutter
晚霞的不甘9 小时前
Flutter for OpenHarmony从基础到专业:深度解析新版番茄钟的倒计时优化
android·flutter·ui·正则表达式·前端框架·鸿蒙
Warren989 小时前
Pytest Fixture 作用域详解:Function、Class、Module、Session 怎么选
面试·职场和发展·单元测试·pytest·pip·模块测试·jira
鸟儿不吃草9 小时前
android的Retrofit请求https://192.168.43.73:8080/报错:Handshake failed
android·retrofit
Minilinux201810 小时前
Android音频系列(09)-AudioPolicyManager代码解析
android·音视频·apm·audiopolicy·音频策略
李子红了时10 小时前
【无标题】
android
Android系统攻城狮11 小时前
Android tinyalsa深度解析之pcm_close调用流程与实战(一百零四)
android·pcm·tinyalsa·音频进阶·音频性能实战·android hal
weixin_4111918411 小时前
LifecycleEventObserver和DefaultLifecycleObserver使用
android
、BeYourself12 小时前
Intent :跳转与数据传递的正确打开方式
android·android-studio