簡體   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