Robot Framework未创建文件或未写入文件 [英] Robot Framework not creating file or writing to it

查看:140
本文介绍了Robot Framework未创建文件或未写入文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Python脚本,它接受一个日志级别并将其设置为默认级别,因此,一旦通过日志消息,它将根据级别层次结构打印或不打印(即,如果默认值为DEBUG,则所有消息都将打印) ,只有CRITICAL& ERROR消息(如果默认为ERROR).

I have a Python script that takes in a log level and sets that to the default level, so once log messages are passed through, it will print or not print according to the level hierarchy (i.e. all messages print if default is DEBUG, only CRITICAL & ERROR messages if default is ERROR).

我的Python代码遵循以下原则:

My Python code is along the lines of this:

# Sets default log level.
def set_default_level(self,level):
    levels = {
        'DEBUG': logging.DEBUG,
        'INFO': logging.INFO,
        'WARNING': logging.WARNING,
        'ERROR': logging.ERROR,
        'CRITICAL': logging.CRITICAL
    }

    # Sets up configuration for logging message.
    logging.basicConfig(format='%(levelname)s: %(message)s', filename = 'log_file.log', filemode = 'w', level=levels[level])

def log_message(self, lvl, message):
    msg_print = {
        '[DEBUG]': logging.debug,
        '[INFO]': logging.info,
        '[WARNING]': logging.warning,
        '[ERROR]': logging.error,
        '[CRITICAL]': logging.critical
    } 
    msg_print[lvl](message)

此代码仅在单独运行Python时起作用.但是,当我使用Robot Framework运行此代码时,它不是在创建/写入文件.我目前拥有的框架就是这样的:

This code DOES work while running Python alone. However, when I run this code with Robot Framework, it's not creating/writing to the file. The framework I have currently is along the lines of this:

Test Validate Info Prints
    [Documentation]     Checks if all BUT debug messages are printed.
    ...                 Output should not contain any DEBUG level messages.
    Set Default Level   ${INFO_LVL}
    Log Message         ${DEBUG}               ${DEBUG_MSG}
    Log Message         ${INFO}                ${INFO_MSG}
    Log Message         ${ERROR}               ${ERROR_MSG}
    Log Message         ${WARNING}             ${WARNING_MSG}
    Log Message         ${CRITICAL}            ${CRITICAL_MSG}

    ${LogFile}=         Get File                ./log_file.log

    Should contain      ${LogFile}      this build has no associated authentication!
    Should contain      ${LogFile}      S3 Bucket connected successfully
    Should contain      ${LogFile}      No working Internet connection available
    Should contain      ${LogFile}      Application has failed.

    Should not contain   ${LogFile}      please debug this

这仅测试INFO默认级别.其他测试用例与此非常相似,但是所有测试用例在创建文件时都存在相同的问题.我已经调查了这个问题,但没有发现任何用处.我最初使用PowerShell运行框架,然后切换到Git BASH并遇到了同样的问题.我也在Windows 7上运行.

This is only testing the INFO default level. Other test cases are very similar to this one, but all of them are having the same issue with file creation. I've looked into the issue, but haven't found anything of use. I was using PowerShell at first to run the framework, then I switched to Git BASH and same issue. I am also running on Windows 7.

提前谢谢!

推荐答案

尝试了您的代码!并且我已经开始相信这是预期的行为.

Tried with your code! and I have started believing that it is expected behavior.

为什么?,因为必须使用代码中使用的同一"Logging" python库来处理Robot Framework中的登录.

Why?, because logging in Robot Framework must be handled using the same "Logging" python library that you are using in your code.

因此,当您实际传递[INFO],[DEBUG]或任何其他消息时,实际上您并未创建新的记录器,这与将其传递给Robot Framework的现有记录器一样好!因此,我们在机器人框架的log.html中看到了所有消息.如下:

So, when you are actually passing your [INFO], [DEBUG] or any other messages, you are in fact not creating a new logger, it would be as good as passing it to the existing logger of the Robot Framework! Hence we see all the messages in the log.html of robot framework. as below:

20161209 12:24:58.497   WARN    Application has failed.     
20161209 12:24:58.499   WARN    No working Internet connection available    
20161209 12:24:58.501   WARN    this build has no associated authentication!

不过这只是一个想法!

这篇关于Robot Framework未创建文件或未写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆