python – 如何在行为中看到print()语句(BDD)
作者:互联网
上下文:我使用Python with Behave(BDD).
无论我是从命令行(行为)还是从自定义main()运行我的测试,行为都是相同的:测试运行,我在控制台中看到的唯一输出是标准BDD报告.
我的测试包括帮助我调试代码的print()语句.但是,当我运行时,控制台输出中没有显示这些打印语句.
我们有什么方法可以“行为”在我们的代码中显示print语句吗?
我的主要()
config = Configuration()
if not config.format:
default_format = config.defaults["default_format"]
config.format = [ default_format ]
config.verbose = True
r = runner.Runner(config)
r.run()
if config.show_snippets and r.undefined_steps:
print_undefined_step_snippets(r.undefined_steps)
我的test.feature文件:
Feature: My test feature with the Behave BDD
Scenario: A simple test
Given you are happy
When someone says hi
Then you smile
我的test_steps.py文件:
from behave import given, when, then, step, model
@given('you are happy')
def step_impl(context):
pass
@when ('someone says {s}')
def step_impl(context, s):
context.message = s
print("THIS IS NEVER DISPLAYED IN THE CONSOLE")
pass
@then ('you smile')
def step_impl(context):
assert(context.message == "hi")
解决方法:
从命令行,您可以使用以下内容:
– 不捕获任何要立即打印的stdout输出.
–no-capture-stderr可立即打印任何stderr输出.
标签:python,bdd,python-behave 来源: https://codeday.me/bug/20190928/1827036.html