How can I tell robot framework not to log a keyword?

这一生的挚爱 提交于 2019-12-23 09:32:03

问题


In a robot framework test case I set a variable and then do a process.

Because the setting of the variable is not a very interesting bit of information, I don't want to include that in my report.

| Verifying STUFF  |
| | ${endpoint}=    | set variable | STUFF
| | Verify

My report contains this:

KEYWORD: ${endpoint} = BuiltIn.Set Variable STUFF

But I would rather not have it there. How can I tell Robot Framework to just not log that line?

------edit------

It looks like this should do it:

pybot --removekeywords NAME:SetVariable testcase.txt

But the Set Variable keywords are still there.

(And yes, I upgraded my robot framework to 2.8.3 to take advantage of this function.)


回答1:


The best you can do is to use

Set Log Level    NONE

but it will still log all the keyword calls, just not anything inside those.

Or if you call a python function which calls another function, then the call to the second function is not logged.

Like this:

*** Settings ***
Library           lib.py

*** Test Cases ***
demo
    Set Log Level    NONE
    ${a}    foo
    xyzzy

*** Keywords ***
xyzzy
    qwerty

qwerty
    No Operation
    Log    123

and lib.py being like this:

def foo():
    abc = bar()
    return abc

def bar():
    c = 1
    print c
    return c



回答2:


You can use --removekeywords or --flattenkeywords option on pybot to remove the content of keyword So if you have e.g. keyword "foo" that contains lot's of logging keywords, you can set "--flattenkeywords name:foo" option to pybot, and In the log you'll only see the primary keyword, but no keywords inside it.

http://robotframework.googlecode.com/hg/doc/userguide/RobotFrameworkUserGuide.html?r=2.8.3#removing-and-flattening-keywords




回答3:


The problem is that when you assign a variable like ${var} = Keyword, the name of the keyword in Robot Framework outputs is ${var} = Keyword, not Keyword as you would expect. If your keyword is from a library or a resource file, its name will also be included like ${var} = MyLibrary.Keyword. The latter is a feature but the former is a bug that is hopefully fixed in RF 2.9.

An easy workaround for the keyword name, for now, including the variable name is using wildcards. Something like this ought to work for you:

--RemoveKeywords 'name:* = BuiltIn.Set Variable'



回答4:


If you use a python library, the following monkey-patching works for me:

from robot.libraries.BuiltIn import BuiltIn
from robot.output.logger import LOGGER
import types

def _nothing(*args, **kwargs):
    pass

def disable_keyword_logging(self):
    self._logging_methods = (LOGGER.start_keyword, LOGGER.end_keyword)
    LOGGER.start_keyword = types.MethodType(_nothing,LOGGER)
    LOGGER.end_keyword = types.MethodType(_nothing,LOGGER)

def enable_keyword_logging(self):
    LOGGER.start_keyword, LOGGER.end_keyword = self._logging_methods

Then when this script is run:

Disable keyword logging
Log    Hello world
Enable keyword logging

the "Log" keyword is not logged to the output but the output is. If you really want nothing (also no debug/info/warn information logged by the called keywords), you will still have to set the log level to "NONE".




回答5:


Robot Framework doesn't log "global" variables as part of a variable table. Global is in quotation marks because Set Global Variable actually is logged, but if you initialize your variable like so...

*** Variables ***
${endpoint}     stuff

*** Keywords ***

...then it will not be in the Log. Additionally, if you don't want anyone to see the variable at all if they're just looking at the front end of your testing suite, you can bury it in a Resource file and the call the Resource file.

Robot Framework logs your Set Variable keywords and results because Set Variable implies that you're setting a variable dynamically and might be setting it based on the result of a keyword, in which case you'd probably want to know what the result of the keyword is. If you're just creating a static variable, then no extra work beyond the table is required. Is a dynamic variable a required part of your code?



来源:https://stackoverflow.com/questions/20008953/how-can-i-tell-robot-framework-not-to-log-a-keyword

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!