1

I have a variable file which defines a variable like dictionary in dictionary and variable functions.

global.py

DEFAULT_VAL=111
TEST_VAR={'key1':{'elem1':'val1', 'elem2':'val2', 'elem3':'val3'}, 'key2':{'elem2':'val2', 'elem3':'val3'}}

def get_elem1_or_default_1(key):
   return   TEST_VAR[key]['elem1'] if 'elem1' in TEST_VAR[key] else DEFAULT_VAL

def get_elem1_or_default_2(key_dict):
   return   key_dict['elem1'] if 'elem1' in key_dict else DEFAULT_VAL

From robot I can call variable function 'get_elem1_or_default_1' which accept string as key, like this:

*** Settings ***
Variables           Global.py

${var}    Set variable    ${get_elem1_or_default_1('key2')}
INFO : ${var} = 111

But when I try to call another function 'get_elem1_or_default_2' which accept dict as argument I get an error

${key_dict}   Evaluate   ${TEST_VAR}['key1']
${var}    Set variable    ${get_elem1_or_default_2(${key_dict})}

INFO : ${key_dict} = {'elem2': 'val2', 'elem3': 'val3', 'elem1': 'val1'} FAIL : Invalid variable name '${get_elem1_or_default_2({'elem2': 'val2', 'elem3': 'val3', 'elem1': 'val1'})}'.

Is it possible to do so or something is wrong? May be there is another way?

Thanks!

1 Answer 1

1

Your "variable functions" are just functions that should be called as keywords and not as variables. So you you can keep your global.py as it is, but call your functions this way:

*** test cases ***
mytest
  ${key_dict} =   Evaluate  ${TEST_VAR}['key1']
  ${var} =  get_elem1_or_default_2  ${key_dict} 
Sign up to request clarification or add additional context in comments.

2 Comments

Hello. Thanks for your comment. But there is some problem. I load variables file as *** Settings *** Variables Global.py And when I try to use "variable functions" as keyword I get an error: no keyword found.
yes, you have to load it as library (library Global)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.