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"])
相关推荐
百锦再7 小时前
React编程高级主题:测试代码
android·前端·javascript·react.js·前端框架·reactjs
2501_916008898 小时前
全面介绍Fiddler、Wireshark、HttpWatch、SmartSniff和firebug抓包工具功能与使用
android·ios·小程序·https·uni-app·iphone·webview
玉梅小洋9 小时前
Windows 10 Android 构建配置指南
android·windows
Libraeking10 小时前
视觉篇:Canvas 自定义绘图与高级动画的华丽圆舞曲
android·经验分享·android jetpack
Fushize11 小时前
多模块架构下的依赖治理:如何避免 Gradle 依赖地狱
android·架构·kotlin
Jomurphys12 小时前
Kotlin - 类型别名 typealias
android·kotlin
Haha_bj12 小时前
Flutter ——flutter_screenutil 屏幕适配
android·ios
Haha_bj12 小时前
Flutter ——device_info_plus详解
android·flutter·ios
前端小伙计12 小时前
Android/Flutter 项目统一构建配置最佳实践
android·flutter
Mr_sun.14 小时前
Day09——入退管理-入住-2
android·java·开发语言