【发布时间】:2022-09-28 19:34:52
【问题描述】:
版本信息 蟒蛇:3.9 表现:1.2.6 魅力:2.13.5
我有 1 个功能和 1 个场景,3 个步骤会故意失败(它们都有 ZeroDivError)。
特征文件内容如下所示(test.feature)
Feature: Zero division
Scenario: people
Given Alex divides a number by zero
Given Tom divides a number by zero
Given Mark divides a number by zero
Python中的步骤实现,
from behave import *
@given(u\'Alex divides a number by zero\')
def step_impl(context):
try:
a= 5
quotient= a/0
print(quotient)
except:
raise Exception(\"ZeroDivisionError has happened ALEX\")
@given(u\'Tom divides a number by zero\')
def step_impl(context):
try:
t= 10
quotient= t/0
print(quotient)
except:
raise Exception(\"ZeroDivisionError has happened TOM\")
@given(u\'Mark divides a number by zero\')
def step_impl(context):
try:
m= 15
quotient= m/0
print(quotient)
except:
raise Exception(\"ZeroDivisionError has happened MARK\")
在每一步中,我所做的就是将一个数字除以 0 并为其引发异常。
运行以下命令后在终端中看到的输出
行为特征\\test.feature
输出:TLDR -> 这里没有问题,所有步骤都失败并引发 3 个 ZeroDivisionerrors
> Feature: Zero division # features/test.feature:1 > > Scenario: people # features/test.feature:2 > > Given Alex divides a number by zero # features/steps/test.py:4 > Traceback (most recent call last): > File \"features\\steps\\test.py\", line 8, in step_impl > quotient= a/0 > ZeroDivisionError: division by zero > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File \"PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\behave\\model.py\", > line 1329, in run > match.run(runner.context) > File \"\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\behave\\matchers.py\", > line 98, in run > self.func(context, *args, **kwargs) > File \"features\\steps\\test.py\", line 11, in step_impl > raise Exception(\"ZeroDivisionError has happened ALEX\") > Exception: ZeroDivisionError has happened ALEX > > Given Tom divides a number by zero # features/steps/test.py:13 > Traceback (most recent call last): > File \"features\\steps\\test.py\", line 17, in step_impl > quotient= t/0 > ZeroDivisionError: division by zero > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File \"\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\behave\\model.py\", > line 1329, in run > match.run(runner.context) > File \"\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\behave\\matchers.py\", > line 98, in run > self.func(context, *args, **kwargs) > File \"features\\steps\\test.py\", line 20, in step_impl > raise Exception(\"ZeroDivisionError has happened TOM\") > Exception: ZeroDivisionError has happened TOM > > Given Mark divides a number by zero # features/steps/test.py:23 > Traceback (most recent call last): > File \"features\\steps\\test.py\", line 27, in step_impl > quotient= m/0 > ZeroDivisionError: division by zero > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File \"\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\behave\\model.py\", > line 1329, in run > match.run(runner.context) > File \"\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\behave\\matchers.py\", > line 98, in run > self.func(context, *args, **kwargs) > File \"features\\steps\\test.py\", line 30, in step_impl > raise Exception(\"ZeroDivisionError has happened MARK\") > Exception: ZeroDivisionError has happened MARK > > > > Failing scenarios: features/test.feature:2 People > > 0 features passed, 1 failed, 0 skipped 0 scenarios passed, 1 failed, 0 > skipped 0 steps passed, 3 failed, 0 skipped, 0 undefined Took 0m0.009s自然我得到了想要的输出,所有 3 个步骤都失败了。这里没有问题
现在我运行这个命令来创建魅力报告
表现 -f allure_behave.formatter:AllureFormatter -o ALLURE/features/test.feature
接下来我运行 allure serve 命令,在浏览器中打开 allure 报告。 这就是我的问题开始的地方。
我正在链接魅力报告-> https://cosmic-narwhal-c18273.netlify.app/#
这就是为什么在类别下只引发了一个异常,即 ZeroDivisionError 发生在 ALEX 上
为什么我在测试缺陷下看不到其他失败的步骤。
它只显示场景的第一个例外
如何配置 allure 以显示每个失败的步骤及其异常。我错过了什么吗?
请协助
-
不熟悉这些库或工具,只是在这里说您不应该使用裸露的
except。 -
@ddejohn 明白了,我就在这里
标签: python allure python-behave