Pybot - 将测试库打印语句重定向到控制台
Pybot - redirect test library print statements to the console
Test.robot,
*** Settings ***
Library roppie
*** Test Cases ***
Log Test
Robot Print
roppie.py,
def robot_print():
print "this is a testlib log for robot test - Test.robot"
现在,当我运行pybot Test.robot
时,打印语句打印在log.html中。但我有兴趣在控制台、stdout 流中看到这些打印语句。
由于 log.html 有很多文本标记,我更喜欢在控制台上以纯文本形式查看日志消息。如何配置?
机器人重新定义sys.stdout
。机器人框架用户指南中标记为 Logging Information 的部分提到了这一点(请参阅副标题 "Logging to console"。
Another option, that is only available with Python, is writing
messages to sys.__stdout__ or sys.__stderr__. When using this
approach, messages are written to the console immediately and are not
written to the log file at all
例如:
import sys
def robot_print():
sys.__stdout__.write("this is a testlib log for robot test - Test.robot")
或者,如果您不是 "a fan of this java like print statements..."(根据您对原始问题的评论),您可以暂时重新分配 sys.stdout
:
def robot_print():
pybot_stdout = sys.stdout
sys.stdout = sys.__stdout__
print "this is a testlib log for robot test - Test.robot"
sys.stdout = pybot_stdout
But I am interested in seeing these print statements in the console, stdout stream.
为此,我使用内置库中的 Log to console。
示例:
from robot.libraries.BuiltIn import BuiltIn
bi=BuiltIn()
def robot_print():
bi.log_to_console("this is a testlib log for robot test - Test.robot")
Test.robot,
*** Settings ***
Library roppie
*** Test Cases ***
Log Test
Robot Print
roppie.py,
def robot_print():
print "this is a testlib log for robot test - Test.robot"
现在,当我运行pybot Test.robot
时,打印语句打印在log.html中。但我有兴趣在控制台、stdout 流中看到这些打印语句。
由于 log.html 有很多文本标记,我更喜欢在控制台上以纯文本形式查看日志消息。如何配置?
机器人重新定义sys.stdout
。机器人框架用户指南中标记为 Logging Information 的部分提到了这一点(请参阅副标题 "Logging to console"。
Another option, that is only available with Python, is writing messages to sys.__stdout__ or sys.__stderr__. When using this approach, messages are written to the console immediately and are not written to the log file at all
例如:
import sys
def robot_print():
sys.__stdout__.write("this is a testlib log for robot test - Test.robot")
或者,如果您不是 "a fan of this java like print statements..."(根据您对原始问题的评论),您可以暂时重新分配 sys.stdout
:
def robot_print():
pybot_stdout = sys.stdout
sys.stdout = sys.__stdout__
print "this is a testlib log for robot test - Test.robot"
sys.stdout = pybot_stdout
But I am interested in seeing these print statements in the console, stdout stream.
为此,我使用内置库中的 Log to console。 示例:
from robot.libraries.BuiltIn import BuiltIn
bi=BuiltIn()
def robot_print():
bi.log_to_console("this is a testlib log for robot test - Test.robot")