Skip to content

Too earlier evaluate the keyword's arguments of Run keywork if  #62

Closed

Description

@spooning

Originally submitted to Google Code by DeonWu on 12 Aug 2008

What steps will reproduce the problem?
|Run keyword if| 1 == 2 | Log | ${MESSAGE} |

raised 'Non-existing variable '${MESSAGE}', if not defined the
'${MESSAGE}', even the keyword 'Log' never called.

The problem can avoid by adding a user keyword, like:
|Run keyword if| 1 == 2 | Log Message |
but it's more simply if to delay evaluating the arguments of called keyword.

What is the expected output? What do you see instead?
the ${MESSAGE} is evaluated in 'Log' running.

Please provide any additional information below.

following just is a temporary solution.
robot>svn di

Index: running/handlers.py

--- running/handlers.py (revision 404)
+++ running/handlers.py (working copy)
@⁠@⁠ -61,7 +61,17 @⁠@⁠
else:
lib_instance = self.library.get_instance()
handler = self._get_handler(lib_instance, self._handler_name)

  •    args = self._process_args(args, namespace.variables)
    
  •    if self.name in ['Run Keyword If']:
    
  •        #to delay evaluating the arguments of called keyword.
    
  •        base_args, kw_args = args[:2], map(BundingVariable, args[2:])
    
  •        args = self._process_args(base_args, namespace.variables)
    
  •        args.extend(kw_args)
    
  •    else:
    
  •        args = map(lambda (x):isinstance(x, BundingVariable) and x.name or
    
    x,
  •                   args)
    
  •        args = self._process_args(args, namespace.variables)
    
    • self._tracelog_args(output, args)
      utils.capture_output()
      try:
      @⁠@⁠ -299,3 +309,11 @⁠@⁠
      self._copy_attributes(handler)
      handler._run_keyword_method_name = self._run_keyword_method_name
      return handler
    +class BundingVariable(object):
  • def init(self, name):
  •    self.name = name
    
  • def str(self):
  •    return self.name
    
    \ No newline at end of file

Activity

  1. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by DeonWu on 12 Aug 2008

    a common way is supporting a specially tag in keywords docs.
    like:

    def run_keyword_if(self, expr, name, *args):
    """Runs the given keyword with the given arguments, if 'expr' is true.
    @⁠BindVarible:2:
    ^^^^^^^^^^^^^^^
    """

    def run_keyword(self, name, *args):
    """Executes the given keyword with the given arguments.
    @⁠BindVarible:1:
    ^^^^^^^^^^^^^^^
    """"

  2. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @pekkaklarck on 26 Aug 2008

    I understand the problem, but I don't think it's that severe. First of all there
    shouldn't be that many cases where 'Run Keyword If' (or 'Run Keyword Unless') are
    needed, and there are also two workarounds.

    1. Use the variable in a user keyword. If the keyword is not executed it doesn't
      matter if it uses a variable that does not exist.

    2. Initialize the variable into some default value so that it always exists. Doesn't
      fully work e.g. with list variables or with extended variable syntax, but at least it
      should work in most cases.

    I'm not against fixing this problem, though, but since it doesn't have too high
    priority we probably won't do it in the near future. If you can provide a fix with
    tests things are different. The patch in the description is a good start but it has
    some problems and could be simplified. I'll comment it separately.

  3. spooning commented on Jun 29, 2014

    @spooning
    ContributorAuthor

    Originally submitted to Google Code by @pekkaklarck on 26 Aug 2008

    As an interesting coincidence, Juha noticed today that a problem with huge log files
    he was investigating was at least partly caused by different 'Run Keyword' variants
    resolving their arguments too early. In his case the problem was that when the final
    keyword was executed, variables in its arguments where shown in resolved format in
    output files. Some of the variables contained quit big values which made output files
    really big.

    I just submitted a new issue 67 about the new problem. The problem this issue is a
    subset of that, which makes this issue a duplicate. Thanks for submitting this issue
    and for the patch in the description. The final solution will have same idea
    underneath, but we need to add some more logic around it. See issue 67 for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions