Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging not captured on behave steps

Ok so in my environment.py file I am able to log stuff by:

logging.basicConfig(level=logging.DEBUG, filename="example.log")

def before_feature(context, feature):
    logging.info("test logging")

but when I am inside the steps file I cannot perform logging:

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)

@given("we have a step")
def step_impl(context):
    logger.debug("Test logging 2")

The logging message inside the step does not show up. I am using the python behave module. Any ideas?

I have tried enabling and disabling logcapture when I run behave but it makes no difference.

like image 626
nnja Avatar asked Sep 09 '16 01:09

nnja


2 Answers

By default, behave tends to capture logs during feature execution, and only display them in cases of failure.

To disable this, you can set log_capture=false in behave.ini

Or, you can use the --no-logcapture command line option

Further Reading : Behave API Reference, Behave LogCapture

like image 147
pixie999 Avatar answered Nov 16 '22 12:11

pixie999


what worked for me:

behave --no-capture --no-capture-stderr --no-logcapture

and add in the environment.py the follwing snipest:

    def after_step(context, step):
        print("")

Why: I disovered that behave does not log the last print statement of a step. So I just added a empty print after each step with the previous snipest.

Hope it helped

like image 31
zarathoustra Avatar answered Nov 16 '22 11:11

zarathoustra