pytest + yaml 框架 -47.parameters参数化支持笛卡尔积
前言
v1.3.8 版本对 parameters 参数化格式重新做了定义,支持笛卡尔积了。当然以前旧版本的格式还是继续兼容。
(备注:从v1.2.4 以后新版本不再公开,新功能内部 VIP 学员可以使用,公开版本仅解决bug, 不提供新功能了。)
parameters 参数化
新版本对 parameters 参数化重新做了定义,简化了步骤,更加清晰简洁.
1.只有一个变量需要参数化的情况
test_p1.yml
config:
parameters:
x: ["a", "b", "c"]
test_a:
print: "输出-${x}"
运行结果
test_p1.yml 输出-a
.输出-b
.输出-c
.
2.有2个变量需要参数化的情况,变量中间用逗号隔开(或者-)
test_p2.yml
config:
parameters:
x,y: [["a", "b"], ['c', 'd']]
test_b:
print: "输出-${x}-${y}"
也可以实现横线隔开
config:
parameters:
x-y: [["a", "b"], ['c', 'd']]
运行结果
test_p2.yml 输出-a-b
.输出-c-d
.
笛卡尔积
对2个变量同时参数化,生成笛卡尔积的情况
x 变量只有一个值,可以写成x: "a"
, 也可以写成x: ["a"]
test_p3.yml
config:
parameters:
x: "a"
y: ["hello", "world"]
test_r:
name: 11
print: "组合-${x}-${y}"
x 变量也可以有多个值
test_p4.yml
config:
parameters:
x: ["a", 'b']
y: ["hello", "world"]
test_r:
name: 11
print: "组合-${x}-${y}"
运行结果
test_p4.yml 组合-a-hello
.组合-a-world
.组合-b-hello
.组合-b-world
.
模块级别和用例级别参数化
支持模块级别和用例级别参数化
- config 中 parameters 参数化,作用域是整个模块级别
- 用例中 parameters 参数化,作用域只针对单个用例
用例级别参数化
test_p5.yml
config:
name: demo
test_1:
name: 用例1
parameters:
user: [hello, world]
print: "case-${user}"
运行结果
test_p5.yml case-hello
.case-world
.
config 中 parameters 参数化,作用域是整个模块级别, test_p6.yml 文件示例
config:
parameters:
x: ["a", 'b']
y: ["hello", "world"]
test_a:
print: "组合-${x}-${y}"
test_b:
print: "组合-${x}-${y}"
运行结果
test_p6.yml 组合-a-hello
.组合-a-hello
.组合-a-world
.组合-a-world
.组合-b-hello
.组合-b-hello
.组合-b-world
.组合-b-world
.
网易云完整视频课程https://study.163.com/course/courseMain.htm?courseId=1213419817&share=2&shareId=480000002230338
报名咨询wx:283340479 (已报名的同学学习过程中有问题,都可以协助解决)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步