繁体   English   中英

从 python 记录到机器人框架不适用于 subprocess.call

[英]logging from python to robot framework not working for subprocess.call

我有一个名为 Log 的 function ,它将日志字符串写入机器人框架日志文件。 如果我从定义的 A.py 中调用此 function,它会按预期登录到 output.html。 But if i call this function from another python function init.py which in turn is invoked from A.py itself using subprocess.call, It does not log into output.html. 它只是忽略它。 一个.py:

def Log( logString,typeOfLog):
        ts = time.time()
        st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
        print(st)
        if typeOfLog=="INFO":
                logger.console(st + '  ' + logString)
                logger.info(logString)
        elif typeOfLog=="DEBUG":
                logger.console(st + '  ' + logString)
                logger.debug(logString)
        elif typeOfLog=="WARN":
                logger.console(st + '  ' + logString)
                logger.warn(logString)
        elif typeOfLog=="ERROR":
                logger.console(st + '  ' + logString)
                logger.error(st + '  ' + logString)
        elif typeOfLog=="":
                logger.console(logString)
                logger.trace(logString)
.
.
.
.
def Test():
        Log("My debug statement in DEPLOY.PY","INFO")----->gets logged to output.html
        ret = subprocess.call("python init.py", shell=True)
        .
        .
        .

init.py 的代码:

from A import Log
from robot.api import logger
def initfunc1():
        Log("Something","INFO")------>this does not get logged to output.html

initfunc1()

如果有人可以解释为什么会发生这种情况以及如何从 init.py 调用 Log function 也可以登录到 output.html 对我很有帮助。

提前致谢。

subprocess.call开始的进程无权访问机器人框架 (RF) 执行上下文,因为该上下文能够将日志消息写入 RF output 文件(output.xml、log.ZFC35FDC88...A.A7888... )。 在这种情况下,由于进程无法找到上下文, robot.api.logger将使用 python 日志模块记录消息,有关详细信息,请参阅记录器文档

In order to get output from the subprocess to the robot logs, you could use subprocess.run instead of subprocess.call to capture the output of the child process and log this captured output to the RF output. 另请参阅 RF 流程库,了解从 RF 执行流程的另一种方式。

暂无
暂无

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

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