cancel
Showing results for 
Search instead for 
Did you mean: 

Python Error Handling Not Executing Finally Block - TestComplete 14.0

SOLVED
Contributor

Python Error Handling Not Executing Finally Block - TestComplete 14.0

Try/Except works, but an exception is thrown in the except block (seems to refer to this syntax: str(err)) and never makes it to the finally block.  TestComplete 12.6 did not have this issue.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: Python Error Handling Not Executing Finally Block - TestComplete 14.0

Something else to check:

In the TestItems page, right click and select "Field Chooser".  There should be a field of "on exception".  Add that to your test item list.  I BELIEVE this defaults to "Stop test item" on exception. So, you're throwing an "exception" in your code.  This would then prompt the automation to halt on that exception which is why it doesn't get to the "finally" clause.  You can set that to "continue running" as well. See if that corrects your problem.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
9 REPLIES 9
Community Hero

Re: Python Error Handling Not Executing Finally Block - TestComplete 14.0

Please share your code.  It will be easier to debug if we can see what we're debugging.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Community Hero

Re: Python Error Handling Not Executing Finally Block - TestComplete 14.0

OK... just thinking outloud (after doing some research), in Python (and I'm no Python expert) as I understand it the str method converts whatever is in the parentheses into a string.

I don't know for sure (because you haven't shown me your actual code), but I suspect "err" is an object of some sort.  In JavaScript, when you do something like

 

try {

}
catch (e) {

}
finally {

}

In the above code the e is an object with various properties.  So, it doesn't convert, easily, to a string.  If Python does something similar, that could very well be the problem.  

 

Again, seeing your code would be better.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Contributor

Re: Python Error Handling Not Executing Finally Block - TestComplete 14.0

Yes, I believe you are correct.  However, the e had no problems converting in 12.6 (or older versions for that matter).  Something seems to have changed in debugging.  I'm noticing more cryptic debug messages and missing call stack items overall.   May need to rollback to 12.6.   I'll post more when I can be more exact!

Community Hero

Re: Python Error Handling Not Executing Finally Block - TestComplete 14.0

Note, also, error handling has changed in TC 14.

https://support.smartbear.com/testcomplete/docs/general-info/whats-new.html#better-error-handling

 

So, if you're generating an error/exception, depending upon how things were set before the upgrade and how you have your Test Items configured, it may simply be a matter of tweaking a setting so that the project continues running and logging call stacks, errors, and finally blocks.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Contributor

Re: Python Error Handling Not Executing Finally Block - TestComplete 14.0

More info:

* All settings within TC appear correct

* I no longer get a full stack trace in TC 14.0 "Script Test Log" only the error caught in the "except" statement (12.6 did not have this issue)

* When I remove the try/except/finally I get a full stack trace and more exact error message (which is clickable to the code).  The problem of course, is that I need the finally block.

* It seems to me TC 14.0 is not correctly handling the Python try/except/finally blocks (again, no issues at all with 12.6)

Community Hero

Re: Python Error Handling Not Executing Finally Block - TestComplete 14.0

Please screenshot and post:

 

1) Tools -> Current Project Properties -> Playback

2) View -> Organize Tests

 

Again, as mentioned, the over all handling of errors and how it affects the run of a test, has changed in TC 14... see the link I sent before.  So, what it SOUNDS like is that there is an error getting logged that is triggering an immediate halt to the test execution which then supercedes the "finally" block. You say the settings are "correct", but what was "correct" in TC 12.6 may no longer be "correct" in TC 14.  So... if you can get those screenshots, that will help us help you better.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Contributor

Re: Python Error Handling Not Executing Finally Block - TestComplete 14.0

Yes, I have read your replies.  Thank-you for quick responses. 

1) All 3 settings in Playback Error handling are "Continue running"

2) All settings for tests in "test items" "on error" are "Use project's 'On Error' property" [so that I can set groups globally as needed].  I've also tried the other settings to check behavior.

 

It appears that Python's try/except/finally overrides all TC settings & worse, masks other exceptions/call stack.  At least that's the behavior I see.  Take out the try/except/finally block and everything runs as in previous TC versions.

Community Hero

Re: Python Error Handling Not Executing Finally Block - TestComplete 14.0

Something else to check:

In the TestItems page, right click and select "Field Chooser".  There should be a field of "on exception".  Add that to your test item list.  I BELIEVE this defaults to "Stop test item" on exception. So, you're throwing an "exception" in your code.  This would then prompt the automation to halt on that exception which is why it doesn't get to the "finally" clause.  You can set that to "continue running" as well. See if that corrects your problem.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Community Manager

Re: Python Error Handling Not Executing Finally Block - TestComplete 14.0

Hi All,

Thanks for your help, Robert!

@exdunepilot, have you come to the solution? If you are still looking for the solution, I suggest that you contact our Support Team and explain the issue in detail. If you suspect that TestComplete doesn't handle the try-catch block correctly - we will need to test it in our test lab. You can contact the Team here:

http://support.smartbear.com/message/?prod=TestComplete

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
New Here?
Join us and watch the welcome video:
Watch the new interview
Top Kudoed Authors