You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For a given test case, you may call the Fail keyword at any time, but you cannot call it during the Test Teardown phase.
Detail
If Fail is called as the last step in a test case, setting the case status (including any msg you supply) works fine.
However, if you attempt to call this keyword during the test teardown phase, you will get the following if you don't include a message: Teardown failed: AssertionError
If you do include a message, the HTML tag isn't honored:
Here is an example of a keyword that does work if it is called as the last step in a test case, and should work if called as a Test Teardown:
Finish Test Messages [Documentation] This runs fine if called inline with a test case, ... however, it will fail if called from Test Teardown
Run Keyword If ${test_fail_count} > 0 Fail msg=*HTML* ${test_messages}
... ELSE Set Test Message *HTML* ${test_messages}
Suggested Fix Approaches
Don't allow this keyword to throw an assertion merely because it is called in the test teardown phase.
If the above is not acceptable, update the documentation to reflect that it cannot be called during any teardown phase (test or suite).
My guess is that using *HTML* doesn't work because the actual error is prefixed with Teardown failed:. The same problem would occur also with continuable failures if there are more than one failure. I'm not sure how easy this is to fix but I can take a look. Can you clarify is there some other issue than this?
@pekkaklarck - I'm assuming that as well. I guess my point is - why is teardown failing? Unless I flag the test case as failed, it appears to pass and the HTML is rendered correctly. Only if I mark it as failed (per my keyword example, if the ${test_fail_count} is greater than zero) will it blow up.
My point is this - if you have the Fail built-in keyword executing during test teardown, it says that teardown failed. That was an unexpected behavior to me. I would have thought that teardown failing would have meant that whatever action(s) I had specified for teardown couldn't be completed. Is the Fail keyword out of scope at that point? Otherwise, it seems that it should work on test case teardown (I would understand if I tried to do this at Suite teardown).
*** Test Cases ***API - Lender Management Routes [Documentation] = Case Steps = ... ... | *Step* | *Verification Action* | ... | _1._ | Retrieve Package Label File response is good. | ... | _2._ | Get Address Validation response is good. | ... | _3._ | Evaluate pass/fail within test case. |[Tags] positive API get smoke Given Get Package Label File Response Is Good
And Get Package Address Validate Is Good
Then Finish Test Messages
This Throws the Assert
*** Settings ***Test Teardown Finish Test Messages
*** Test Cases ***API - Lender Management Routes [Documentation] = Case Steps = ... ... | *Step* | *Verification Action* | ... | _1._ | Retrieve Package Label File response is good. | ... | _2._ | Get Address Validation response is good. |[Tags] positive API get smoke Given Get Package Label File Response Is Good
Then Get Package Address Validate Is Good
How Finish Test Messages behaves depends on ${test_fail_count}. Without a full executable example I cannot really comment is the behavior correct or not.
Notice that Fail doesn't do anything more than raise AssertionError(msg) and thus isn't any different to any other keyword that could potentially fail in teardown.
Notice also that you could simplify Finish Test Messages like this:
*** Keywords ***Finish Test Messages
Should Be True ${test_fail_count} == 0 msg=*HTML* ${test_messages}
Set Test Message *HTML* ${test_messages}
When ${test_fail_count} is zero, the test message is set and formatted just fine. Even if I strip all of that out and just do this at Test Teardown:
Finish Test Messages
Fail
then I still get the Teardown failed: AssertionError in the Message column of the report. If I don't call Fail then no assertion happens. Again, it only happens if it is called during teardown - it doesn't happen if it is called as one of the steps (logically, the last) of the given test case.
So - is this by design? If so, then the documentation for this keyword should include a note: "If this keyword is executed during Test Teardown, an assert will be output to the test message."
If this was not by design... 🪲
IMO, it would be preferable for this to be usable during teardown such that the test case author could determine whether the case passed or failed.
Fail always fails with message AssertionError if you use it without an explicit message. In teardown the only difference is that you get that additional Teardown failed: prefix.
OK, @pekkaklarck - I've probably wasted enough of your time on this. I appreciate it!
So if I understand you correctly, if I want to do my own eval and set Fail on a test case, I need to do it before teardown or I'll get the "teardown failed" message, along with it ignoring the *HTML* formatting "switch" - yes?
If so - I understand, even though it's kind of a bummer that I must have one additional step in each and every test case to do this vs. just one time in the Test Teardown. 😢
Activity
pekkaklarck commentedon Apr 27, 2016
My guess is that using
*HTML*doesn't work because the actual error is prefixed withTeardown failed:. The same problem would occur also with continuable failures if there are more than one failure. I'm not sure how easy this is to fix but I can take a look. Can you clarify is there some other issue than this?GLMeece commentedon Apr 27, 2016
@pekkaklarck - I'm assuming that as well. I guess my point is - why is teardown failing? Unless I flag the test case as failed, it appears to pass and the HTML is rendered correctly. Only if I mark it as failed (per my keyword example, if the
${test_fail_count}is greater than zero) will it blow up.My point is this - if you have the
Failbuilt-in keyword executing during test teardown, it says that teardown failed. That was an unexpected behavior to me. I would have thought that teardown failing would have meant that whatever action(s) I had specified for teardown couldn't be completed. Is theFailkeyword out of scope at that point? Otherwise, it seems that it should work on test case teardown (I would understand if I tried to do this at Suite teardown).Let me know if my reply doesn't make sense. 😕
GLMeece commentedon Apr 27, 2016
To further illustrate...
This Works!
(nothing declared for Test Teardown):
This Throws the Assert
@pekkaklarck - Is that any more helpful? 🔍
pekkaklarck commentedon Apr 27, 2016
How
Finish Test Messagesbehaves depends on${test_fail_count}. Without a full executable example I cannot really comment is the behavior correct or not.Notice that
Faildoesn't do anything more thanraise AssertionError(msg)and thus isn't any different to any other keyword that could potentially fail in teardown.Notice also that you could simplify
Finish Test Messageslike this:GLMeece commentedon Apr 27, 2016
When
${test_fail_count}is zero, the test message is set and formatted just fine. Even if I strip all of that out and just do this at Test Teardown:Finish Test Messages Failthen I still get the
Teardown failed: AssertionErrorin the Message column of the report. If I don't callFailthen no assertion happens. Again, it only happens if it is called during teardown - it doesn't happen if it is called as one of the steps (logically, the last) of the given test case.So - is this by design? If so, then the documentation for this keyword should include a note: "If this keyword is executed during Test Teardown, an assert will be output to the test message."
If this was not by design... 🪲
IMO, it would be preferable for this to be usable during teardown such that the test case author could determine whether the case passed or failed.
pekkaklarck commentedon Apr 27, 2016
Failalways fails with messageAssertionErrorif you use it without an explicit message. In teardown the only difference is that you get that additionalTeardown failed:prefix.GLMeece commentedon Apr 27, 2016
OK, @pekkaklarck - I've probably wasted enough of your time on this. I appreciate it!
So if I understand you correctly, if I want to do my own eval and set Fail on a test case, I need to do it before teardown or I'll get the "teardown failed" message, along with it ignoring the
*HTML*formatting "switch" - yes?If so - I understand, even though it's kind of a bummer that I must have one additional step in each and every test case to do this vs. just one time in the Test Teardown. 😢
pekkaklarck commentedon Apr 28, 2016
I think
Teardown failedis good but it breaking HTML is definitely bad. A separate bug should be submitted about it.GLMeece commentedon Apr 28, 2016
@pekkaklarck - hopefully issue 2360 gives you what you need. Let me know if it does not.
pekkaklarck commentedon May 31, 2016
Closing in favor of #2360.