Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not print to console, or log pretty much at all. #346

Closed
jeremyjjbrown opened this issue Jul 21, 2015 · 9 comments
Closed

Does not print to console, or log pretty much at all. #346

jeremyjjbrown opened this issue Jul 21, 2015 · 9 comments
Labels

Comments

@jeremyjjbrown
Copy link

Behave Version: 1.2.5
Python Version: 2.7.8

Neither

print "foo"
from __future__ import print_function
print("foo")

outputs anything to the console. Even with

 behave --no-capture

Also given that logging.debug() prints nothing unless and error is thrown makes debugging absolutely impossible. I've tried

behave --logging-level=INFO
context.config.setup_logging(configfile="behave_logging.ini")

...

[handler_Console]
class=StreamHandler
args=(sys.stderr,)
level=INFO
formatter=Brief

perhaps it has to do with a missing

# -- FILE:features/environment.py
from behave.log_capture import capture

@capture
def after_scenario(context):
    ...

but the doc is inscrutable. What is to be added to the hook block? And why does behave not just print to the console like any sane application would?

@jenisys
Copy link
Member

jenisys commented Jul 21, 2015

Actually, it does. Using --no-capture directly outputs the text. That is at least my experience.

  • Where are you using the print statements (step implementation, environment) ?
  • Which OS are you using ?

Note that

  • logging.debug() will never output anything if the logging.level is INFO.
  • capture mode captures text and log-output until a failure occurs. Then it shows the collected output. Output of passing scenarios will be silently dropped.

If you always want to output something (always), use --no-capture mode or use log-filters to allow that some logging categories are not captured (meaning they are excluded from capture-mode).

@lizhaode
Copy link

@jenisys
I use behave --no-capture but it doesn't work.
For example,
I print('abc'),but I can't see abc in console when I running behave --no-capture

@jenisys
Copy link
Member

jenisys commented Mar 20, 2017

@lizhaode
Your are mistaken. See answer in your other ticket.

@manoadamro
Copy link

I have the same problem:
am running behave -i observations --no-capture --no-capture-stderr -D BEHAVE_DEBUG_ON_ERROR

and only some print statements are getting printed.

eg:

this used to print but stopped:

    if context.debug:
        print("ENCOUNTER UUID: %s" % encounter["uuid"])

this does not print:

        if context.debug:
            print(
                f"received pdf: {number_of_pages} pages, {number_of_bytes} bytes "
            )

this does print:

        if context.debug:
            print(
                f"received pdf: {number_of_pages} pages, {number_of_bytes} bytes "
                f"(expecting > {number_of_pages} pages, > {number_of_bytes} bytes)"
            )

all of the steps are running but only some print statements actually print :(

@jeremyjjbrown
Copy link
Author

It's awesome being gaslighted by the maintainers because it still doesn't work or is so inscrutable that you can't figure out how to make it work.

@glenn-barker
Copy link

@jeremyjjbrown @jenisys I've had issues with behave "eating" my console output even when using the --no-capture flag. Turns out it's the default formatter that seems to overwrite my output in certain use cases / certain IDEs.

Adding the --format plain flag in addition to --no-capture fixed the issue for me, and I'm able to see my console output properly.

@gnikonorov
Copy link

@glenn-barker's answer fixed the issue for me

@sangajala
Copy link

"behave --no-capture --format plain" this worked for me

@markodelgadillo
Copy link

I have this same issue. Yes "behave --no-capture --format plain" did work for me as well, but the question remains why DOESN'T "behave --no-capture" work on its own?

It's pretty random and I delete and then type in print statements and sometimes that works. This is my code right now:

from behave import given, when, then

@given('I am in the main directory')
def create_new_user(context):
    print("print now!")
    print("print this too!")
    pass

@when("I click on login")
def click_login(context):
    print("I just clicked on the Login cta")

@then('I should also be in the main directory')
def landing_page(context):
    print("this better print!")
    print("this too!!!")
    print("and this!!!")
    pass

and this is the output:

Feature: Test Cases Group 1 # feature_1.feature:1

  Scenario: Running Test Case 1                 # feature_1.feature:3
    Given I am in the main directory            # steps/steps_1.py:3
print now!
    Given I am in the main directory            # steps/steps_1.py:3 0.000s
    Then I should also be in the main directory # steps/steps_1.py:13
this better print!
this too!!!
    Then I should also be in the main directory # steps/steps_1.py:13 0.000s

1 feature passed, 0 failed, 0 skipped
1 scenario passed, 0 failed, 0 skipped
2 steps passed, 0 failed, 0 skipped, 0 undefined
Took 0m0.000s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants