当前位置:网站首页>pytest接口自动化测试框架 | 单个/多个参数
pytest接口自动化测试框架 | 单个/多个参数
2022-08-01 07:12:00 【COCOgsta】
视频来源:B站《冒死上传!pytest接口自动化测试框架(基础理论到项目实战及二次开发)教学视频【软件测试】》
一边学习一边整理老师的课程内容及试验笔记,并与大家分享,侵权即删,谢谢支持!
附上汇总贴:pytest接口自动化测试框架 | 汇总_COCOgsta的博客-CSDN博客
函数数据参数化
方便测试函数对测试数据的获取。
方法:
parametrize(argnames, argvalues, indirect=False, ids=None, scope=None)
常用参数:
argname:参数名
- argvalues:参数对应值,类型必须为list
- 当参数为一个时格式:[value]
- 当参数个数大于一个时,格式为:[(param_value1, param_value2, ...), (param_value1, param_value2, ...)]
使用方法:
@pytest.mark.parametrize(argnames, argvalues)
参数值为N个,测试方法就会运行N次
单参数
import pytest
# a参数被赋予2个值,函数会运行2遍
@pytest.mark.parametrize("a", ['aaa', 'bbb'])
# 参数必须和parametrize里面的参数一致
def test_01(a):
print('\n' + a)
if __name__ == '__main__':
pytest.main(['-s', 'test_single_param.py'])多参数
import pytest
# a参数被赋予2个值,函数会运行2遍
@pytest.mark.parametrize("a,b", [('zz', '123456'), ('xz', '123456')])
# 参数必须和parametrize里面的参数一致
def test_01(a, b):
print('\n' + a)
print('\n' + b)
if __name__ == '__main__':
pytest.main(['-s', 'test_multi_param.py'])边栏推荐
- 仿牛客网项目总结
- 实战演练 Navicat 中英文模式切换
- MVVM项目开发(商品管理系统一)
- Why is the lightweight VsCode used more and more?Why eat my C drive 10G?How to Painlessly Clean VsCode Cache?Teach you how to lose weight for C drive
- Electromagnetic compatibility introductory tutorial (6) test project
- 最小生成树
- Self-made a remote control software - VeryControl
- Monitor the width and height of the parent element, adapt to the size of the plug-in
- "By sharing" northwestern university life service | | bytes a second interview on three sides by HR
- Using FiddlerScript caught poly FiddlerScript 】 【 download
猜你喜欢
随机推荐
我三本学历,五面阿里,被面试官“供”着出来了,拿了33*15的Offer
Generate pictures based on the content of the specified area and share them with a summary
How to use Photoshop to composite star trail photos, post-processing method of night sky star trail photos
POJ1287联网题解
Golang: go static file processing
Srping中bean的生命周期
小程序通过云函数操作数据库【使用get取数据库】
安装SQL Server详细教程
return;代表含义
从购买服务器到网站搭建成功保姆级教程~超详细
Monitor the width and height of the parent element, adapt to the size of the plug-in
聊一聊ICMP协议以及ping的过程
crypto-js uses
The BP neural network based on MATLAB voice characteristic signal classification
实战演练 Navicat 中英文模式切换
好的plm软件有哪些?plm软件排行榜
Electromagnetic compatibility introductory tutorial (6) test project
JSON 与 JS 对象的区别
仿牛客网项目总结
Leetcode第 304 场周赛









