【发布时间】:2021-09-16 21:55:06
【问题描述】:
当前用例: 假设我有一个名为 X 的独立 Python 库。
- 我使用我创建的使用机器人侦听器的机器人库调用 X。
- 我调用的 X 库使用 Python 的日志记录模块进行日志记录。
- 不应修改 X 库本身以使用 Robot 进行控制台日志记录的方式。
我想要做的是,当我运行 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 记录来自侦听器的消息?
【问题讨论】:
标签: python python-3.x robotframework