当前位置: 首页 > news >正文

深圳网站制作可选兴田德润深圳网络提速优化服务包

深圳网站制作可选兴田德润,深圳网络提速优化服务包,现在做网站用什么工具,西安做推广优化的公司BDD - Python Behave Retry 机制 引言Behave RetryBehave Retry 应用feature 文件创建 step 文件Retry运行 Behave 并生成 rerun 文件重新运行失败的场景 引言 在日常运行测试用例,有时因为环境不稳定造成一些测试用例跑失败了,如果能将这些失败的测试用…

BDD - Python Behave Retry 机制

  • 引言
  • Behave Retry
  • Behave Retry 应用
    • feature 文件
    • 创建 step 文件
    • Retry
      • 运行 Behave 并生成 rerun 文件
      • 重新运行失败的场景

引言

在日常运行测试用例,有时因为环境不稳定造成一些测试用例跑失败了,如果能将这些失败的测试用例再跑一遍,排除环境问题导致的不稳定,从而可以节省每天 triage 的时间。Behave 也有 retry 机制,今天就来了解一下吧。

想了解更多 Behave 相关的文章,欢迎阅读《Python BDD Behave 系列》,持续更新中。

Behave Retry

behave -f rerun 是 Behave 提供的一种输出格式(formatter),用于生成 “rerun” 格式的输出。-f rerun 选项可用于将测试失败的场景(Scenarios)输出到一个文件,然后可以使用这个文件来重新运行失败的测试。

以下是使用 behave -f rerun 的简单示例:

  1. 运行 Behave 并将失败的场景输出到 rerun 文件:
behave -f rerun -o failed_scenarios.txt

这个命令将运行测试并将失败的场景信息输出到 failed_scenarios.txt 文件中。生成的 rerun 文件包含了失败场景的标识符,如 features/my_feature.feature:3,这样 Behave 能够准确识别并重新运行这些场景。

  1. 重新运行失败的场景:
behave @failed_scenarios.txt

此命令将重新运行 failed_scenarios.txt 文件中列出的所有失败场景。

注意上面的命令有可能会执行失败因为 @ 符号异常,我们可以换另外一种方式执行,加上双引号""

behave "@failed_scenarios.txt"

Behave Retry 应用

举个简单的例子,项目结构如下:

在这里插入图片描述

feature 文件

创建 my_feature.feature 文件

Feature: Example FeatureScenario: Failing ScenarioGiven I have a failing stepWhen I perform an actionThen I should see a result

创建 step 文件

创建 my_steps.py 文件

from behave import given, when, then@given('I have a failing step')
def step_given(context):assert False, "Simulating a failure in the Given step"@when('I perform an action')
def step_when(context):print("When step executed")@then('I should see a result')
def step_then(context):print("Then step executed")

Retry

运行 Behave 并生成 rerun 文件

执行测试用例: behave Features/Retry -f rerun -o failed_scenarios.txt
将跑失败的测试用例输出到 failed_scenarios.txt 文件中。

PS C:\Automation\Test\bdd> behave Features/Retry -f rerun -o failed_scenarios.txtFailing scenarios:Features/Retry/my_feature.feature:3  Failing Scenario0 features passed, 1 failed, 0 skipped
0 scenarios passed, 1 failed, 0 skipped
0 steps passed, 1 failed, 2 skipped, 0 undefined       
Took 0m0.000s

当前目录生成 failed_scenarios.txt,文件内容列出失败 Scenario 的路径及行数。
在这里插入图片描述

重新运行失败的场景

执行命令 behave @failed_scenarios.txt
抛异常了:The splatting operator '@' cannot be used to reference variables in an expression

PS C:\Automation\Test\bdd> behave @failed_scenarios.txt      
At line:1 char:8
+ behave @failed_scenarios.txt
+        ~~~~~~~~~~~~~~~~~
The splatting operator '@' cannot be used to reference variables in an expression. '@failed_scen 
arios' can be used only as an argument to a command. To reference variables in an expression use '$failed_scenarios'.+ CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException+ FullyQualifiedErrorId : SplattingNotPermitted

换另外一种方式,将 @failed_scenarios.txt 用双引号包装一下。
执行命令 behave “@failed_scenarios.txt”

此命令将重新运行 failed_scenarios.txt 文件中列出的所有失败场景。在这个例子中,由于步骤定义中的 Given 步骤故意失败,Behave 将重试执行这个场景,并且你会看到类似于以下的输出:

PS C:\Automation\Test\bdd> behave "@failed_scenarios.txt"
Feature: Example Feature # Features/Retry/my_feature.feature:1Scenario: Failing Scenario    # Features/Retry/my_feature.feature:3Given I have a failing step # steps/my_steps.py:3Assertion Failed: Simulating a failure in the Given stepWhen I perform an action    # NoneThen I should see a result  # NoneFailing scenarios:Features/Retry/my_feature.feature:3  Failing Scenario0 features passed, 1 failed, 0 skipped
0 scenarios passed, 1 failed, 0 skipped
0 steps passed, 1 failed, 2 skipped, 0 undefined
Took 0m0.000s
http://www.yayakq.cn/news/724763/

相关文章:

  • 怎么做外网网站监控软件电子商务网站建设程序的开发
  • 科技杭州网站建设江门网站制作模板
  • 用app怎么样建网站电子商务网站开发成本
  • 深圳哪家公司需要网站建设的网站权限设置
  • 文山建设局网站莱芜装修网站
  • 微信公众平台网站建设新闻报道怎样做婚恋网站
  • 浙江城乡与住房建设部网站美食网站设计风格
  • 登陆建设银行网站异常网站怎么做动态图
  • 电子商务网站建设清华大学网站数据分析
  • 网站seo优化推广怎么做深圳东维亚建设公司
  • 网站建设求职简历模板下载手机网速
  • 注册自己的网站需要多少钱企业网络营销策划方案设计
  • 如何找外包网站来做php网站建设培训班
  • 美乐乐网站源码wordpress识别手机跳转网站
  • 免费网站制作软件平台苏州建设工程招标网站
  • 家禽养殖公司网站怎么做删除自豪的采用wordpress
  • 广州 行业 网站建设网站设计职业工作室
  • 织梦网站空间如何清理wordpress如何设置404
  • wordpress 站群注意重庆建设机电有限公司网站
  • 网站模板之家项目建设成效怎么写
  • 6免费建站的网站用vs2005做网站设计
  • 怎么做装球的网站上海seo推广
  • 网站如何优化流程工贸一体化企业建设电子商务网站的误区
  • 做网站和APP需要多少钱wordpress插件h5
  • 网站建设空格怎么打网站怎样防止攻击
  • 网站建立好了自己怎么做优化专业做外贸网站的公司
  • 广告字在线制作湖南网站搜索排名优化电话
  • 给别人建设网站的注意事项网站建设规划书 百度文库
  • 网络营销成功案例3篇成都企业网站优化服务
  • 中国体育新闻最新消息360优化大师下载官网