首页 > 其他分享 >pytest + yaml 框架 -69.新增depend 关键字,导入其它yaml用例

pytest + yaml 框架 -69.新增depend 关键字,导入其它yaml用例

时间:2024-05-09 21:57:58浏览次数:13  
标签:depend name 用例 yaml pytest test config yml

前言

有小伙伴提到,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

标签:depend,name,用例,yaml,pytest,test,config,yml
From: https://www.cnblogs.com/yoyoketang/p/18183131

相关文章

  • Springboot - [06] yaml语法讲解
    Yaml是一种标记语言,Yaml也不是一种标记语言。 一、yaml写法示例application.yaml#普通的key-valuename:harleyserver.port:8081#对象student:name:harleyage:25#对象的行内写法student:{name:harley,age:25}#数组pets:-cat-......
  • 代理 mitmproxy config.yaml 模板 使用笔记(二)
    代理mitmproxyconfig.yaml模板使用笔记(二)mitmproxyconfig.yaml模板使用mitmproxy可能需要用到config.yaml来批量配置参数目录config.yaml文件所在位置config.yaml配置模板文件位置配置文件默认读取路径:~/.mitmproxy/config.yaml,见配置项:confdir:'~/.mitmpro......
  • dbt 自定义AdapterPlugin 中dependencies 简单说明
    结合dbt-redshift的对于dependencies部分的定义以及使用简单说明下参考代码Plugin:AdapterPlugin=AdapterPlugin(adapter=RedshiftAdapter,#type:ignorecredentials=RedshiftCredentials,include_path=redshift.PACKAGE_PATH,dep......
  • pytest 学习 - 00 环境安装配置
    前言pytest是一个非常好用且成熟的全功能Python测试框架,个人觉得比传统的Unitest好多用了,现在面试如果写只会Unitest会被鄙视的。主要有以下特点:1.简单灵活,容易上手,参数化灵活。2.测试用例支持很多机制像skip、xfail、自动失败重试等处理。3.能够......
  • goctl快速创建k8s yaml
    安装goctlGO111MODULE=onGOPROXY=https://goproxy.cn/,directgoget-ugithub.com/tal-tech/go-zero/tools/goctlgoctlkubedeploy-namenginx-namespacetest-imagenginx:alpine-replicas1-minReplicas1-maxReplicas3-onginx-j.yaml-port80-nodePort......
  • pytest lastfailed原理
    相信很多使用pytest的,都知道pytest有运行上次失败用例的参数,如下:--lf,--last-failedrerunonlytheteststhatfailedatthelastrun(orallifnonefailed)--ff,--failed-firstrunalltests,butrunthelastfailuresfirst.Thism......
  • python读取yaml配置文件的方法
    yaml简介1.yaml[ˈjæməl]:YetAnotherMarkupLanguage:另一种标记语言。yaml是专门用来写配置文件的语言,非常简洁和强大,之前用ini也能写配置文件,看了yaml后,发现这个更直观,更方便,有点类似于json格式2.yaml基本语法规则:大小写敏感使用缩进表示层级关系缩进时不允许使用Ta......
  • 修复 Debian 安装 dotnet 失败 depends on ca-certificates
    本文记录我在Debian安装dotnet失败,报错信息是packages-microsoft-proddependsonca-certificates;however:Packageca-certificatesisnotinstalled.一开始按照官方的以下代码例子进行安装packages-microsoft-prod.deb文件,命令如下sudodpkg-ipackages-microsof......
  • python之pytest
    安装pipinstallpytest 终端运行pytest:在当前目录中查找并运行所有符合测试用例命名规范的测试用例。pytest-q:以简化模式运行所有测试用例。pytest-v:以详细模式运行所有测试用例。pytesttest_sample.py:运行指定的测试文件test_sample.py中的所有测试用例。......
  • SnakeYaml反序列化分析
    前言SnakeYaml是Java中解析yaml的库,而yaml是一种人类可读的数据序列化语言,通常用于编写配置文件等。yaml真是到哪都有啊。环境搭建<dependency><groupId>org.yaml</groupId><artifactId>snakeyaml</artifactId><version>1.32</version></dependency>SPI机制介绍......