コンテキスト: Python と Behave (BDD) を使用しています。
テストをコマンド ライン (behave) から実行する場合でも、カスタムの main() から実行する場合でも、動作は同じです。テストが実行され、コンソールに表示される出力は標準の BDD レポートだけです。
テストには、コードのデバッグに役立つ print() ステートメントが含まれています。ただし、これらの print ステートメントは、behavior を実行したときにコンソール出力に表示されません。
コード内の 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")