How to output "Fail" when a testing script returns exit code(1)?

*** Settings ***
Documentation Stream

Library Stream.py

*** Test Cases ***
Play Stream
Stream

*** Keywords ***
Stream
play item=rtsp

The script(Stream.py) will return exit code(1) when encountering fail case.
However, the robot framework will stop testing(no report generated) instead of showing “Fail” when getting the exit code(1) from the script.

What should I do so that the robot framework can output “Fail” when the script return exit code(1)?

OS: Windows 11
Python: 3.12.0
Robotframework: 7.0.1

Hi,

From your description, the .py script throw an exception with code (1), so of course as error is in the script RF stops.
You should use a Try/Expect in your .py to catch this exception, then return something to RF.
Then when calling your script as keyword you can use a variable to get return code and use Fail keyword to stop test. Something like this:

*** Keywords ***
Stream
   ${statuscode}    play item=rtsp
   IF    ${statuscode}  == 1    Fail    msg=yourmessage

Regards
Charlie

Hello,

Thank you for your reply.
Due to unexpected problem, the script will output another exit code: Process finished with exit code -1073740791 (0xC0000409) when I manually raise an exception in the .py script.

That’s why I must use “sys.exit(1)” to output the return code(1) when encountering a fail case.

Is there any way that I can avoid RF stop and it can output Fail in the situation? Thanks.

What about using the Process library to run your test script? Rather than importing your script as a library.

With Run Process you can get the script stdout, stderr and return code. See example.

1 Like

Hello @FrancisG,

Thank you for your advise. I got it working with process library.

2 Likes