Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
607 views
in Technique[技术] by (71.8m points)

python - How can I see print() statements in behave (BDD)

Context: I am using Python with Behave (BDD).

Whether I run my tests from the command line (behave) or from a custom main(), the behavior is the same: the test runs and the only output that I see in the console is the standard BDD report.

My tests include print() statements that help me debug my code. However, none of these print statements are being displayed in the console output when I run behave.

Is there any way we can have "behave" display the print statements in our code?

My Main()

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)

My test.feature file:

Feature: My test feature with the Behave BDD
    Scenario: A simple test
    Given you are happy
    When someone says hi
    Then you smile

My test_steps.py file:

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")
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

from command line, you can use the following:

--no-capture for any stdout output to be printed immediately.

--no-capture-stderr for any stderr output to be printed immediately.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[3] html - How to create even cell spacing within a

1.4m articles

1.4m replys

5 comments

57.0k users

...