user2381567 user2381567 - 2 months ago 43x
Python Question

How to use extra arguments passed with Variable file - Robot framework

In Robot Framework user guide there is a section that describes how to pass variable files and also some possible variables if needed.


pybot --variablefile

My question is can i use these possible variables arg1 and arg2 in the file afterwards and if i can then how?

Right now i have this:

pybot --variablefile contents:

IP_PREFIX = arg1

But that results in

NameError: name 'arg1' is not defined


The only way to use variables in an argument file using the --variablefile syntax is to have your variable file implement the function get_variables. This function will be passed the arguments you specify on the command line, and must return a dictionary of variable names and values.

For example, consider the following variable file, named "":

def get_variables(arg1, arg2):
    variables = {"argument 1": arg1,
                 "argument 2": arg2,
    return variables

This file creates two robot variables, named ${argument 1} and ${argument 2}. The values for these variables will be the values of the arguments that were passed in. You might use this variable file like this:

pybot --variablefile ...

In this case, the strings "one" and "two" will be passed to get_variables as the two arguments. These will then be associated with the two variables, resulting in ${argument 1} being set to one and ${argument 2} being set to two.