gpt4 book ai didi

python - 在场景大纲之前运行某些步骤一次 - Python Behave

转载 作者:太空狗 更新时间:2023-10-30 01:33:18 36 4
gpt4 key购买 nike

如标题所示,我希望在场景大纲之前运行一些特定的配置/环境设置步骤。我知道有 Background 可以针对场景执行此操作,但 Behave 将场景大纲拆分为多个场景,从而为场景大纲中的每个输入运行后台。

这不是我想要的。由于某些原因,我无法提供我正在使用的代码,但我会编写一个示例功能文件。

Background: Power up module and connect
Given the module is powered up
And I have a valid USB connection

Scenario Outline: Example
When I read the arduino
Then I get some <'output'>

Example: Outputs
| 'output' |
| Hi |
| No |
| Yes |

在这种情况下会发生的情况是 Behave 会重新启动并检查每个输出的 USB 连接 HiNoYes,结果是三个电源循环和三个连接检查

我想要的是让 Behave 重新启动一次并检查一次连接,然后运行所有三个测试。

我该怎么做?

最佳答案

您最好的选择可能是使用 before_feature 环境 Hook ,并且 a)特征上的标签和/或 b) 直接特征名称。

例如:

一些.feature

@expensive_setup
Feature: some name
description
further description

Background: some requirement of this test
Given some setup condition that runs before each scenario
And some other setup action

Scenario: some scenario
Given some condition
When some action is taken
Then some result is expected.

Scenario: some other scenario
Given some other condition
When some action is taken
Then some other result is expected.

steps/environment.py

def before_feature(context, feature):
if 'expensive_setup' in feature.tags:
context.execute_steps('''
Given some setup condition that only runs once per feature
And some other run once setup action
''')

替代步骤/environment.py

def before_feature(context, feature):
if feature.name == 'some name':
context.execute_steps('''
Given some setup condition that only runs once per feature
And some other run once setup action
''')

关于python - 在场景大纲之前运行某些步骤一次 - Python Behave,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34126474/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com