【发布时间】:2014-02-26 15:16:23
【问题描述】:
我们最近开始将Behave (github link) 用于新python Web 服务的BDD。
问题
在测试失败时,我们有什么方法可以获取有关失败原因的详细信息?他们抛出AssertionError,但他们从不显示到底出了什么问题。例如进入断言的期望值和实际值。
我们一直在努力寻找这样的现有功能,但我想它不存在。当然,这个问题的一个很好的答案是提示和提示如何通过修改源代码来实现此行为,以及此功能是否存在于其他类似的 BDD 框架中,例如 jBehave、NBehave 或 Cucumber?
示例
今天,当测试失败时,输出显示:
Scenario: Logout when not logged in # features\logout.feature:6
Given I am not logged in # features\steps\logout.py:5
When I log out # features\steps\logout.py:12
Then the response status should be 401 # features\steps\login.py:18
Traceback (most recent call last):
File "C:\pro\venv\lib\site-packages\behave\model.py", line 1037, in run
match.run(runner.context)
File "C:\pro\venv\lib\site-packages\behave\model.py", line 1430, in run
self.func(context, *args, **kwargs)
File "features\steps\login.py", line 20, in step_impl
assert context.response.status == int(status)
AssertionError
Captured stdout:
api.new_session
api.delete_session
Captured logging:
INFO:urllib3.connectionpool:Starting new HTTP connection (1): localhost
...
我想要类似的东西:
Scenario: Logout when not logged in # features\logout.feature:6
Given I am not logged in # features\steps\logout.py:5
When I log out # features\steps\logout.py:12
Then the response status should be 401 # features\steps\login.py:18
ASSERTION ERROR
Expected: 401
But got: 200
如您所见,我们通用步骤中的断言清楚地打印出来
`assert context.response.status == int(status)`
但我宁愿有这样的功能
assert(behave.equals, context.response.status, int(status)
或任何其他可以从失败的断言中生成动态消息的东西。
【问题讨论】:
标签: cucumber bdd jbehave nbehave python-behave