Ask a Question

How to do test specific on stop event (clean up)?

SOLVED
jsan
Occasional Contributor

How to do test specific on stop event (clean up)?

Hi, it seems like Testcomplete (TC) has its own event handling when a Stop event occurs so the 'finally' on this test does not run. But TCs event handling is a global one (I think). How can I do a test specific cleanup on a Stop event?

 

def test1():
    try:
        Log.Error("Error")
    finally:
        Log.Message("Do cleanup for test1")

 

def test2():
    try:
        Log.Error("Error")
    finally:
        Log.Message("Do cleanup for test2")

1 REPLY 1
joseph_michaud
Moderator

You're using a Log.Error() to cause a Stop.  If your project's Playback option "Stop on error" was not set, then you would return from the error to do the cleanup.  No Stop event would occur.

 

If you changed your example to do a Stop directly, then there's not much more you can do after a Stop event.  You won't be returning from the Stop event handler.

 

You could load data into a Project variable and then do something based on that:

 

 

 

def foo():
Log.Message("cleanup for test2")

def test2(): try: Project.Variables.cleanup = 1 Runner.Stop() finally: Log.Message("will never get here") def GeneralEvents_OnStopTest(Sender): if Project.Variables.cleanup == 1: foo() Log.Message("OnStopTest done")

 

 

but don't be surprised if you can't do much more than this.

-----
Joseph
cancel
Showing results for 
Search instead for 
Did you mean: