1

有人可以告诉我,我怎样才能获得behave在 python 中运行的场景的状态?

我想获取方法中运行的测试用例的状态(成功或错误)after_scenario

4

2 回答 2

3

从 Behave 1.2.6 开始,状态是一个枚举,所以:

# -file- environment.py
from behave.model_core import Status

def after_scenario(context, scenario):
    print(Scenario.status)

    if scenario.status == Status.failed:
        print('more details:...')

import仅用于将状态与 进行比较,Status.failed例如打印更多详细信息。

status是场景运行的只读摘要:

  • Status.untested:该场景尚未完全测试。

  • Status.skipped:此场景的一个或多个步骤在测试期间被忽略。

  • Status.passed:场景测试成功。

  • Status.failed:此方案的一个或多个步骤失败。

在 1.2.6 版更改:使用状态枚举类(原为:字符串)

请参阅:http ://behave.readthedocs.io/en/stable/api.html#behave.model.Scenario.status

于 2018-04-24T17:42:52.267 回答
2

这很容易用行为来完成。该类Scenario有一个名为 的属性status。您可以在这样的after_scenario方法中使用它:

# -file- environment.py

def after_scenario(context, scenario):
    print (scenario.status)

这应该返回以下之一:

  • untested: 该场景尚未完全测试。

  • skipped:在测试期间跳过了此场景的一个或多个步骤。

  • passed: 场景测试成功。

  • failed: 此方案的一个或多个步骤失败。

于 2016-08-15T22:09:04.357 回答