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

Ben

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")
Ben

I figured it out after spending more time reading the documentation. It is actually quite simple. By default, behave does not display any output (i.e. by using print()) unless there is a failure in the test. To force displaying all output regardless of the outcome of the test (pass/fail), all you need is to change some of the default settings. The easiest way to achieve that is to create a file named behave.ini in the root of your project's directory and put the following:

Filename: behave.ini

[behave]
stderr_capture=False
stdout_capture=False

Next time you run your behave tests, you will see all outputs from your debug statements whether your tests pass or fail.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How can I see normal print output created during pytest run?

From Dev

How to see output of print statements when scrapy logger enabled

From Dev

How can I print 413284921265094656?

From Dev

How can I call a constructor after statements?

From Dev

How can I combine these jQuery statements?

From Dev

How can I get code coverage data from Python BDD functional tests using Behave?

From Dev

How can I avoid these case statements?

From Dev

How to disable print statements conveniently so that pythonw can run?

From Dev

How can i create good repeatable date tests in BDD?

From Dev

How can I make echo or printf in shell ignore a double backslash (\\) and print it as I see it

From Dev

How can I print a Maybe?

From Dev

How can I change serenity-bdd log settings

From Dev

How can I reduce this long list of if statements?

From Dev

How can I refactor a set of ugly if statements?

From Dev

How do I skip a test in the behave python BDD framework?

From Dev

How can I print this?

From Dev

How can I combine these jQuery statements?

From Dev

How can I DRY this series of conditional statements?

From Dev

How can i create good repeatable date tests in BDD?

From Dev

How can I combine these two statements?

From Dev

How can I see Debug.Print() statements?

From Dev

Where can I print out logs to see immediately in Android Studio?

From Dev

Where can I see what print_r display on PHP?

From Dev

How can I print these values (see description) in a table?

From Dev

How can I write regex for the following statements?

From Dev

How can I setText for a JLabel so it prints multiple print statements from a void method?

From Dev

How to skip steps in background of Behave BDD?

From Dev

How can I join these two select statements?

From Dev

How can I make this a prepared Statements code?

Related Related

  1. 1

    How can I see normal print output created during pytest run?

  2. 2

    How to see output of print statements when scrapy logger enabled

  3. 3

    How can I print 413284921265094656?

  4. 4

    How can I call a constructor after statements?

  5. 5

    How can I combine these jQuery statements?

  6. 6

    How can I get code coverage data from Python BDD functional tests using Behave?

  7. 7

    How can I avoid these case statements?

  8. 8

    How to disable print statements conveniently so that pythonw can run?

  9. 9

    How can i create good repeatable date tests in BDD?

  10. 10

    How can I make echo or printf in shell ignore a double backslash (\\) and print it as I see it

  11. 11

    How can I print a Maybe?

  12. 12

    How can I change serenity-bdd log settings

  13. 13

    How can I reduce this long list of if statements?

  14. 14

    How can I refactor a set of ugly if statements?

  15. 15

    How do I skip a test in the behave python BDD framework?

  16. 16

    How can I print this?

  17. 17

    How can I combine these jQuery statements?

  18. 18

    How can I DRY this series of conditional statements?

  19. 19

    How can i create good repeatable date tests in BDD?

  20. 20

    How can I combine these two statements?

  21. 21

    How can I see Debug.Print() statements?

  22. 22

    Where can I print out logs to see immediately in Android Studio?

  23. 23

    Where can I see what print_r display on PHP?

  24. 24

    How can I print these values (see description) in a table?

  25. 25

    How can I write regex for the following statements?

  26. 26

    How can I setText for a JLabel so it prints multiple print statements from a void method?

  27. 27

    How to skip steps in background of Behave BDD?

  28. 28

    How can I join these two select statements?

  29. 29

    How can I make this a prepared Statements code?

HotTag

Archive