pytest + yaml 框架 -54. variables 可以引用同一层级变量

发布时间 2023-08-29 20:00:07作者: 上海-悠悠

前言

v1.4.5 新增功能。同一层级variables 变量中,可以引用前面的变量了

  • config 中 variables 可以引用同一层级变量
  • 用例中 variables 可以引用同一层级变量

引用同一层级变量

最近有部分学员遇到的问题,在同一个层级设置变量,后面的变量引用前面的变量(v1.4.4之前的版本不支持)

config 中变量引用示例

config:
  name: yoyo
  variables:
    name: xx
    email: 222@qq.com
    info:
        address: 上海市
        email: ${email}

v1.4.5 新增功能。同一层级variables 变量中,可以引用前面的变量了, 用例运行日志

2023-08-29 19:50:50 [INFO]: config variables-> {'name': 'xx', 'email': '222@qq.com', 'info': {'address': '上海市', 'email
': '222@qq.com'}}

用例中 变量引用示例

config:
  name: yoyo

test_user:
  name: user
  variables:
    name: xx
    email: 222@qq.com
    info:
        address: 上海市
        email: ${email}
  print: ${info}

运行结果

2023-08-29 19:52:10 [INFO]: 运行用例-> test_user
2023-08-29 19:52:10 [INFO]: 取值表达式: email, 取值结果:222@qq.com <class 'str'>
2023-08-29 19:52:10 [INFO]: 取值表达式: info, 取值结果:{'address': '上海市', 'email': '222@qq.com'} <class 'dict'>
{'address': '上海市', 'email': '222@qq.com'}

网易云完整视频课程https://study.163.com/course/courseMain.htm?courseId=1213419817&share=2&shareId=480000002230338
报名咨询wx:283340479