Running python script in robot framework

As I’m new to Robot framework. Im trying to run simple robot file

 *** Settings ***
Library    Process

*** Variables ***
${PYTHON_SCRIPT}    /home/engineer/Demoproject/pythonRobotBluetoothproject/Libraries/

*** Test Cases ***
Run Python Script
    ${result} =    Run Process    python    ${PYTHON_SCRIPT}
    Should Be Equal As Numbers    ${result}    0

Python file


def main():
    print("Hello from")

if __name__ == "__main__":

Im not sure of this error .

Example Test                                                                  
Run Python Script                                                     | FAIL |
'<result object with rc 2>' cannot be converted to a floating point number: TypeError: float() argument must be a string or a real number, not 'ExecutionResult'
Example Test                                                          | FAIL |
1 test, 0 passed, 1 failed

Could anyone help on this?

Hi Soma,

From the Run Process Docs:

Returns a result object containing information about the execution.

This is not a number but a complete result object, so that would explain your error, perhaps what you wanted is something like:

Should Be Equal As Numbers    ${result.rc}    0

A little curious why you choose this route when you should be able to use Evaluate something like this:

Evaluate 	main() 	modules=${PYTHON_SCRIPT}

Remember Robot Framework is written in python, so can easily call any python function internally, no need to go out to a separate python process unless there’s a good reason to do so.


Thanks Dave.Getting error like this after your inputs,
Evaluating expression ‘main() modules= /home/engineer/Demoproject/pythonRobotBluetoothproject/Libraries/’ failed: SyntaxError: invalid syntax (, line 1)

*** Settings ***
Library Process

*** Variables ***
${PYTHON_SCRIPT} /home/engineer/Demoproject/pythonRobotBluetoothproject/Libraries/

*** Test Cases ***
Run Python Script
evaluate main() modules=${PYTHON_SCRIPT}

Hi Soma,

I’ve not used Evaluate exactly like that before, so not sure what the exact syntax should be, I’ve only used it with python modules that are in the path.

So normally that would look something like this:

Evaluate 	main() 	modules=example_script

But that won’t work in your case unless is in the same folder as your robot file.

Perhaps this will work

Evaluate 	main() 	modules=/home/engineer/Demoproject/pythonRobotBluetoothproject/Libraries/example_script

If not I guess you’ll need to play with it a bit to find the exact syntax to make it work,