[英]Logging Python function to log.html like robot keywords
from robot.api.deco import keyword
from robot.api import logger
def decorator():
....
do something
....
class Tester(object):
@keyword
def run_hello(self):
self.hello()
@decorator
def hello(self):
logger.info("hello word")
*** Settings ***
Library Test.py
*** Test Cases ***
Run Hello
Run Hello
When the robot run keyword run_hello
,the python function hello()
can logging to log.html like robot user keyword?当robot run关键字run_hello
,python函数hello()
可以像robot user关键字一样登录到log.html吗? How to write the decorator
function? decorator
函数怎么写?
And I want the log.html like the image:我想要像图像一样的 log.html:
I have solved it.我已经解决了。 And my python code还有我的python代码
from functools import wraps
from robot.libraries.BuiltIn import register_run_keyword
from robot.libraries.BuiltIn import BuiltIn
def robot_run_keyword(func):
@wraps(func)
def func_wrapper(self,*args, **kwargs):
if not hasattr(func, "second"):
setattr(func, "second", True)
ar = list(args)
for key, value in kwargs.items():
ar.append("%s=%s"%(key,value))
register_run_keyword("WiseLibrary",func.__name__,len(ar),deprecation_warning=False)
return BuiltIn().run_keyword(func.__name__, *ar)
else:
delattr(func, "second")
return func(self,*args, **kwargs)
return func_wrapper
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.