Passing a robot variable by reference to a python function

2,791 views
Skip to first unread message

François I

unread,
Mar 23, 2016, 9:33:37 AM3/23/16
to robotframework-users
Hi, I use my own python function in Robot Framework. I give 3 parameters, these parameters are Robot Framework variables. When I modify the variables in my function, they are not modified in Robot Framework. So I deduce the variables are passed by value and not by reference... Is there a way to pass the variable by reference ? Or else to return the 3 variables as a result ?

Here is an example of Robot Framework code :

** Settings ***
 
Library    OperatingSystem
 
Library    myLib.MyLib    WITH NAME    MyLib
 
 
Suite TearDown  teardown
 
** Variables **
 $
{var}  azerty
 
 
** Test Cases **
 
My test case
         log     $
{var}
         myFunction    $
{var}
         log     $
{var}

With my python library :

import sys
 
 
class MyLib(object):
     
def __init__(self):
         
return
 
     
def myFunction(self,var):
         
var="another value"

But as I said, the variable var remains "azerty" when I log it, and I would like the second log to print "another value" (as the function should change the value)

Thank for your help !

Pekka Klärck

unread,
Mar 23, 2016, 9:36:05 AM3/23/16
to franco...@gmail.com, robotframework-users

You are not modifying the value but resetting a variable. In fact you even cannot modify strin

Sent from my mobile.

--
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 https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Pekka Klärck

unread,
Mar 23, 2016, 9:38:13 AM3/23/16
to François I, robotframework-users

Ooopps, sent accidentally, sorry. Was just saying that you cannot even modify strings in Python. If you would pass a mutable object, like a list, changes done by the lib would be seen also on Robot side.

Sent from my mobile.

Kevin O.

unread,
Mar 23, 2016, 4:53:41 PM3/23/16
to robotframework-users
If you are interested in returning multiple variables, check out the user guide. There's an example of returning multiple values.

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#returning-values

Kevin
Reply all
Reply to author
Forward
0 new messages