1

I have a python script which I run as a test in robot framework. The test is configured to log the stdout and stderr which works fine as long as the test pass but I get no logs when test fails even if the output is printed before the failure.

Is there any way to get the stdout even if the tests fails.

My robot file:

*** Settings ***
Library   Process


*** Test Cases ***
First test
    ${result} =     Run Process     python    createCommunityTest/createCommunityTest.py
    Should Be Equal As Integers     ${result.rc}    0    
    Log     ${result.stderr} 
    Log     ${result.stdout}

test script snippet

        if res.status == 201: 
            sys.exit(0)
        else:
            print("ERRRROR")
            sys.exit(1)
6
  • Think it might be down to, RF just stopping the test on fail. So it never actually reaches the 2 log commands... Test it by placing the log before the failed part. Commented Aug 25, 2017 at 11:12
  • I did that, I wrote that also in the question.... Commented Aug 25, 2017 at 11:27
  • Show where you "did that". We need to see how you are logging the result before failing the test case. As written, if the Run process keyword or Should be equal as integers fails, the log statements will never run. Commented Aug 25, 2017 at 12:01
  • Yes it fails because of that reason... because I don't return a sys.exit(0) but a sys.exit(1) Commented Aug 25, 2017 at 12:20
  • 1
    You are misunderstanding the question. It doesn't matter how your process fails. What matters is when you terminate the test by calling Should be equal as integers. Commented Aug 25, 2017 at 12:42

1 Answer 1

3

The problem is that you are calling Log after the test has failed. When you check the return code and the return code is not zero, the test immediately stops running any other statements.

You can solve this simply by calling the Log keyword before checking the return code.

Log     ${result.stderr} 
Log     ${result.stdout}
Should Be Equal As Integers     ${result.rc}    0  
Sign up to request clarification or add additional context in comments.

1 Comment

So obvious but could not see it. Thanks

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.