前言
有小伙伴提到,接口返回一个id值,extract提取到后,后面根据这个id值拼接一个SQL语句,调用查询sql的函数。
这样调用函数的时候传参会嵌套引用另外一个变量。
此功能在v1.2.5 版本上实现
使用示例
在conftest.py 定义任意函数, 传一个变量, 并注册到my_builtins
from pytest_yaml_yoyo import my_builtins
# 作者-上海悠悠 wx:283340479
# blog地址 https://www.cnblogs.com/yoyoketang/
def fun_x(x):
return f"result: {x}"
my_builtins.funo = fun_x
在yaml 用例文件中引用函数,标签传参引用其它变量
test_b1.yml
config:
name: xx
variables:
a: "hello"
b: "world"
test1:
name: 调用函数直接传变量
print: ${fun_x(a)}
test2:
name: 函数参数是字符串引用了变量
print: ${fun_x('select * from xx where name="${b}"')}
执行用例
pytest test_b1.yml
运行结果