Passing Python Dictionary as a value to a single keyword argument

2,749 views
Skip to first unread message

Joseph Lorenzini

unread,
Jul 17, 2015, 6:58:41 PM7/17/15
to robotframe...@googlegroups.com
Hi all,

I have a custom lib, that has a keyword argument. This argument's value is supposed to be a dictionary. In my test case, i used the collections keyword to create a dictionary and then i tried to pass the dictionary as keyword argument to the keyword.

  ${response headers}=  Create Dictionary  header1=value1  header2=value2
   Create Response Code  http_headers=${response headers}

However, this fails with the following error:

got multiple values for argument 'http_headers'

Looks like robots is trying to unpack the dictioanry when its passed in to another keyword. However, I don't want it unpacked. I just want to pass the entire object as a single value to the keyword argument. 

Is there a way to do this?

Thanks,
Joe 

Mark Winspear

unread,
Jul 21, 2015, 10:26:28 AM7/21/15
to robotframe...@googlegroups.com

I have a custom lib, that has a keyword argument. This argument's value is supposed to be a dictionary. In my test case, i used the collections keyword to create a dictionary and then i tried to pass the dictionary as keyword argument to the keyword.

  ${response headers}=  Create Dictionary  header1=value1  header2=value2
   Create Response Code  http_headers=${response headers}

However, this fails with the following error:

got multiple values for argument 'http_headers'

 Does it fail if you use a list variable (@ instead of $)?

Tatu Aalto

unread,
Jul 21, 2015, 3:15:45 PM7/21/15
to markwi...@gmail.com, robotframe...@googlegroups.com
Ugh

Could you create runable example of the failure because this works fine with RF 2.8.7 (Python):
=== example.robot ===
*** Settings ***
Library    Collections
Library    MyLibrary.py

*** Test Cases ***
example
    ${d}    Collections.Create Dictionary
    ...    key1=value1
    ...    key2=value2
    My Keyword    arg=${d}

=== MyLibrary.py ===
def my_keyword(arg):
    print arg
======

-Tatu
--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Joseph Lorenzini

unread,
Jul 25, 2015, 3:20:06 PM7/25/15
to robotframework-users, markwi...@gmail.com, Tatu Aalto
Hi all,

It turns out that it was a user error though the fault handling is pretty opaque. I accidentally forgot to put self in the method's signature so that made  it a class method instead of an instance method. Instead of failing and raising a warning robot framework simply passed in the arguments to the unbound method and that led to some really bizarre behavior.

I suspect there's not a whole lot that the framework can about this because this is just how python works. That said it would be pretty nice if there was some way for the framework to raise a warning about calling class methods -- I just find it really unlikely that anyone would ever want to intentionally do that with RF library.

Joe 

--
You received this message because you are subscribed to a topic in the Google Groups "robotframework-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/robotframework-users/RYjojAIEcqY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to robotframework-u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages