0

I would like to pass a set of named variables to a keyword: Like this:

|  | Bypass | environment=${SystemUnderTest} | device=android |

the keyword is defined in python like this:

def Bypass(**kwargs):
    print "kwargs", kwargs

This fails with this error message:

Keyword 'agents.Bypass' expected 0 arguments, got ...

but if I change the keyword definition slightly, like this

def Bypass(*args):
    print "args", args

the test works and I get this in my log:

INFO args (u'environment=staging', u'device=android')

How can I just pass in my named arguments?

j0k
  • 22,600
  • 28
  • 79
  • 90
Skip Huffman
  • 5,239
  • 11
  • 41
  • 51

1 Answers1

2

Afaik this is not something you can do from keywords. If I needed something this flexible my solution would be as so:

def bypass(kwargs):
    print "kwargs", kwargs

|  | ${kwargs}= | Evaluate | dict(environment=${SystemUnderTest}, device=android)
|  | Bypass | ${kwargs}

Or alternatively

def bypass(*args):
    kwargs = {}
    while args:
        kwargs[args.pop(-2)] = args.pop()
    print "kwargs", kwargs

|  | Bypass | environment | ${SystemUnderTest} | device | android
theheadofabroom
  • 20,639
  • 5
  • 33
  • 65
  • Thanks, that is more or less what I have been doing and the code is getting more and more unreadable. I was trying to fix that. But it seems that the best way is to use as structured Data object. – Skip Huffman Mar 15 '13 at 18:10
  • Hmmm - that signals to me that you are trying to handle too much complex logic in you robotframework code, and should be splitting more of it out into python libraries, but obviously I cannot be sure without having seen your code – theheadofabroom Mar 17 '13 at 17:07