当前位置:网站首页>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'])
边栏推荐
- Introduction to the basic principles, implementation and problem solving of crawler
- Self-made a remote control software - VeryControl
- 从底层结构开始学习FPGA(6)----分布式RAM(DRAM,Distributed RAM)
- 好的plm软件有哪些?plm软件排行榜
- GO错误处理方式
- Zero-code website development tool: WordPress
- 自制一款远程控制软件——VeryControl
- Golang: go get url and form attribute value
- Monitor the width and height of the parent element, adapt to the size of the plug-in
- 安装SQL Server详细教程
猜你喜欢
Image lossless compression software which works: try completely free JPG - C image batch finishing compression reduces weight tools | latest JPG batch dressing tools download
升级为重量级锁,锁重入会导致锁释放?
Information system project managers must recite the work of the core test site (56) Configuration Control Board (CCB)
类似 MS Project 的项目管理工具有哪些
rhcsa 第四天
测试工具(四)Jenkins环境搭建与使用
国内外最顶级的8大plm项目管理系统
Dell PowerEdge Server R450 RAID Configuration Steps
Srping bean in the life cycle
金山打字通 官网 下载
随机推荐
图像基本操作的其他内容
Create, modify and delete tables
The BP neural network based on MATLAB voice characteristic signal classification
POJ1251丛林之路题解
Leetcode第 304 场周赛
Golang:go获取url和表单属性值
How to generate and configure public key certificate in Alipay
Golang: go get url and form attribute value
POJ1287联网题解
mysql中添加字段的相关问题
13 - JUC CountDownLatch concurrent programming
Upgrade to heavyweight lock, lock reentrancy will lead to lock release?
NIO programming
Json对象和Json字符串的区别
第02章 MySQL的数据目录【1.MySQL架构篇】【MySQL高级】
Go 支持 OOP: 用 struct 代替 class
matlab wind speed model wavelet filtering
Compare two objects are the same depth
仿牛客网项目总结
return;代表含义