Passing a python variable to a python file which is run from the robot file

I am running a python file in my .robot file using the below format. I have a python test file ( and a variable file(

Content of the is:

test_username = "user123"

Content of the is:

from Resources import common_variables
myTestUsername = common_variables.test_username

Content of my .robot file is

*** Settings ***
Documentation Tests using Python and Robotframework
Library Process
Variables Resources/

*** Variables ***
{myTestName} {test_username}

*** Test Cases ***
Testing Variable
| | {myTestUserame}= | Set Global Variable | {myTestName}
| | {result}= | run process | python | {TESTPATH} | -v | {myTestName} | | Log to console | hello, world. {myTestName}

I need to pass the value to the “myTestUsername” variable in the from the file. How can I do that?
This code | | ${result}= | run process | python | ${TESTPATH} | -v | ${myTestName} fails to execute.
This line of code | | Log to console | hello, world. ${myTestName} works fine and prints the value of the variable from in the PyCharm’s terminal.

I am very new to robotframework and any help from this community is highly appreciated.

back-up a bit and ask yourself “Why am I doing this?” You can pass variables on the robot command line using the -V, you can specify variables in a *yaml, so why are you attempting to retrieve a variable from python?

--variable myTestUsername:userx

Thank you Steve for your suggestion, I was able to make it work.

On a different problem, I am trying to a similar test in robotframework which is calling a python file using Process. It fails to call the python process on Windows machine whereas it works fine on Mac.
If I run the independently it works.
The 2nd line in the test case also works, which prints the “Hello World” text in console.

Content in my Robotfile is like this:

*** Settings ***
Documentation Sample Test
Library Process

*** Test Cases ***
| | {result}= | run process | python | | | {result}= | log to console | Hello World

Any suggestion on why it fails on Windows will immensely help me. Thank you!

Sharing the actual error message where / how it fails is usually a very good idea to share to get some help.

Also, the code you shared has wonky formatting to not sure that makes things even harder to say anything.

Only thing i can even guess what could be a problem is that you are trying to run “python”, but will the working directory be where the is actually located ? How about if you provide cwd parameters to run process ?

1 Like