Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log with Python logging in Robot Framework

Tags:

I use robot framework 3.0 under Python 2.7.8. Robot framework's documentation (http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#programmatic-logging-apis) states that

In addition to the new public logging API, Robot Framework offers a built-in support to Python's standard logging module. This works so that all messages that are received by the root logger of the module are automatically propagated to Robot Framework's log file.

I made a short library file to test this:

from logging import debug, error, info, warn

def try_logging():
    info("This is merely a humble info message.")
    debug("Most users never saw me.")
    warn("I warn you about something.")
    error("Something bad happened.")

My test case is:

*** Test Cases ***
Logtest
    Try logging

When I run it it is a PASSED case, but nothing logged into the HTML log. The test execution log has the suit and the case and the keyword as it should but when I expand them nothing is logged but the "Start / End / Elapsed" line.

How could I forward the Python logger messages to Robot? As you can see the so called automatic propagation is not working automatically. My goal is to write a library that can be run with or without Robot Fw.

Ty for your help in advance.

like image 842
bardosd Avatar asked Apr 20 '16 09:04

bardosd


1 Answers

After hours of code digging I managed to find the answer. I think it is worth sharing as it may be help you if you have some similar issue.

In my case I had some unused libraries imported. One of them was a class that was instantiated when Robot Framework imported the library file. This object had some logger settings that messed up the defaults, that is why I got no result in the robot log.

Without it I got the expected results and automatic propagation worked fine.

like image 152
bardosd Avatar answered Sep 28 '22 01:09

bardosd