简体   繁体   English

在Robot Framework中使用Python登录进行登录

[英]Log with Python logging in Robot Framework

I use robot framework 3.0 under Python 2.7.8. 我在Python 2.7.8下使用机器人框架3.0。 Robot framework's documentation ( http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#programmatic-logging-apis ) states that 机器人框架的文档( http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#programmatic-logging-apis )指出

In addition to the new public logging API, Robot Framework offers a built-in support to Python's standard logging module. 除了新的公共日志记录API外,Robot Framework还为Python的标准日志记录模块提供了内置支持。 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. 这样可以使模块的根记录器收到的所有消息自动传播到Robot Framework的日志文件。

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. 当我运行它时,它是通过的情况,但是没有任何东西记录到HTML日志中。 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? 如何将Python记录器消息转发给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. 我的目标是编写一个可以在有或没有Robot Fw的情况下运行的库。

Ty for your help in advance. 请提前为您提供帮助。

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. 其中一个是在Robot Framework导入库文件时实例化的类。 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. 没有它,我无法获得预期的结果,并且自动传播效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM