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"])
相关推荐
AsiaLYF21 小时前
kotlin中MutableStateFlow和MutableSharedFlow的区别是什么?
android·开发语言·kotlin
2501_9160088921 小时前
iOS 发布全流程详解,从开发到上架的流程与跨平台使用 开心上架 发布实战
android·macos·ios·小程序·uni-app·cocoa·iphone
4Forsee1 天前
【Android】浅析 Android 的 IPC 跨进程通信机制
android·java
叶羽西1 天前
如何区分Android、Android Automotive、Android Auto
android
用户2018792831671 天前
用 “奶茶店订单系统” 讲懂 MVI 架构
android
LiuYaoheng1 天前
【Android】布局优化:include、merge、ViewStub的使用及注意事项
android·java
Kapaseker1 天前
Kotlin Flow 的 emit 和 tryEmit 有什么区别
android·kotlin
好好学习啊天天向上1 天前
Android Studio 撕开安卓手机投屏
android·智能手机·android studio
Android-Flutter1 天前
android - JPG图片转换HDR图片,heic格式
android
诸神黄昏EX1 天前
Android Build系列专题【篇四:编译相关语法】
android