[英]Console logging from Robot Framework listeners using Python's logging
當前用例:假設我有一個名為 X 的獨立 Python 庫。
我想要做的是,當我運行 Robot Framework 時,我需要能夠對來自 X 的日志進行控制台日志記錄。
似乎 Robot 不會捕獲來自偵聽器的日志(盡管它會捕獲級別比“INFO”更嚴重的日志)。示例庫:
class ExampleLibrary:
ROBOT_LIBRARY_SCOPE = "GLOBAL"
ROBOT_LIBRARY_DOC_FORMAT = "TEXT"
ROBOT_LIBRARY_VERSION = "0.1"
ROBOT_LISTENER_API_VERSION = 2
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
self.ROBOT_LIBRARY_LISTENER = self
self._log = logging.getLogger("ExampleLogger")
self._log.setLevel(logging.NOTSET)
self._log.addHandler(logging.StreamHandler())
self._log.info("Initialized ExampleLibrary")
def _start_suite(self, test_suite, result) -> None:
# We do calls to X here..
# X creates its loggers and sends logs like the following line
self._log.debug("suite started!")
def _end_suite(self, test_suite, result):
# We do calls to X here..
# X creates its loggers and sends logs like the following line
self._log.debug("suite ended!")
def try_log(self):
self._log.debug("trying debug log")
self._log.warning("trying warning log")
self._log.error("trying error log")
示例套件:
*** Settings ***
Library ./ExampleLibrary.py
*** Test Cases ***
Passed Test
TRY LOG
嘗試使用robot suite.robot
運行上述 suite.robot 文件:
Initialized FirstLibrary
==============================================================================
Suite
==============================================================================
[ WARN ] trying warning log
[ ERROR ] trying error log
Passed Test | PASS |
------------------------------------------------------------------------------
Suite | PASS |
1 test, 1 passed, 0 failed
==============================================================================
那么,有沒有辦法讓 Robot Framework 記錄來自偵聽器的消息?
默認情況下,Robot 會隱藏任何調試(和內部)級別的日志記錄。 您可以嘗試使用--loglevel DEBUG
啟用它。 您可以在相關的用戶指南部分查看可用的日志級別。 您還可以通過將環境變量ROBOT_INTERNAL_TRACES
設置為任何非空值來啟用機器人內部函數日志記錄,以查看框架提供的庫中發生的情況。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.