pytest + yaml 框架 -64.新增depend 关键字,导入其它yaml用例
前言
有小伙伴提到,test_a.yml 中已经写了几个流程,test_b.yml 中希望能接着test_a.yml去写用例,于是就需要先导入test_a.yml用例。
为了满足此需求,v1.6.3版本 在config 中新增 depend 关键字。
需求场景
test_a.yml 中已经写了一些用例
config:
variables:
x: hello
y: world
test_x1:
name: xx
request:
method: post
url: http://httpbin.org/post
json:
title: aa
message: bbb
test_x2:
name: xx
print: ${x} -- ${y}
test_b.yml 中可以在config 中添加depend 关键字, test_a.yml和test_a.yml 在同一个目录
config:
depend: test_a.yml
test_b3:
name: xx
print: 输出结果--${y}
那么test_b.yml 就等价于把test_a.yml内容复制过来了
config:
variables:
x: hello
y: world
test_x1:
name: xx
request:
method: post
url: http://httpbin.org/post
json:
title: aa
message: bbb
test_x2:
name: xx
print: ${x} -- ${y}
test_b3:
name: xx
print: 输出结果--${y}
所以会重复执行一次test_a.yml用例,再执行test_b.yml 中的用例。
depend 关键字使用
depend 关键字使用规则:
- 1.只能在 config 中使用,因为它是接着前面一个 yml 用例继续写其他用例。
- 2.目前只支持一个层级的引用如:b 引入a, 不支持多层级引入,如:c引入b, b又引入了a
- 3.depend 后面写用例文件的路径,如果在同一目录,可以直接写文件名称,不在同一个目录,需从项目根目录开始,写相对路径。
当 test_a.yml 用例中有在config 定义变量 variables
config:
variables:
x: hello
y: world
test_x1:
name: xx
request:
method: post
url: http://httpbin.org/post
json:
title: aa
message: bbb
test_x2:
name: xx
print: ${x} -- ${y}
test_b.yml 中没有定义config变量时,会默认读取test_a.yml 用例中定义的变量。
config:
depend: test_a.yml
test_b3:
name: xx
print: 输出结果--${y}
test_b.yml 中也可以定义config 变量,替换test_a.yml中的变量
config:
depend: test_a.yml
variables:
y: aabcc
test_b3:
name: xx
print: 输出结果--${y}
此时 test_b3 用例引用变量${y}
得到的结果就是 aabbcc
当用例中有局部变量时,用例中定义的变量优先级是最高的
config:
depend: test_a.yml
variables:
y: aabcc
test_b3:
name: xx
variables:
y: aa1122
print: 输出结果--${y}
此时 test_b3 用例引用变量${y}
得到的结果就是 aa1122
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2023-05-09 httprunner 4.x学习 - 10.参数化(parameters)引用外部 csv 数据文件 和函数
2023-05-09 httprunner 4.x学习 -9.parameters 参数化
2023-05-09 httprunner 4.x学习 -8.base_url 环境地址的使用
2023-05-09 httprunner 4.x学习 - 7.环境变量.env 的使用
2023-05-09 httprunner 4.x学习 - 6.debugtalk辅助函数的使用
2021-05-09 postman使用教程9-点 code 按钮生成代码段
2020-05-09 Cypress web自动化1-windows环境npm安装Cypress