<p>上下文:我使用Python with Behave(BDD)。</p>
<p>无论是从命令行(behave)还是从自定义main()运行测试,行为都是相同的:测试运行,我在控制台中看到的唯一输出是标准的BDD报告。</p>
<p>我的测试包括帮助我调试代码的print()语句。但是,当我运行behave时,这些print语句都不会显示在控制台输出中。</p>
<p>有没有办法让“behave”在代码中显示print语句?</b></p>
<p>我的主()</p>
<pre><code>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)
</code></pre>
<p>我的test.feature文件:</p>
<pre><code>Feature: My test feature with the Behave BDD
Scenario: A simple test
Given you are happy
When someone says hi
Then you smile
</code></pre>
<p>我的test_steps.py文件:</p>
<pre><code>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")
</code></pre>