Skip TestCase based on previous success/failure

Asked by Kyle VandenLangenberg

Hello,

So I am building a large testing procedure using the Sikuli IDE. Right now it is structured like this:

class xyz(unittest.TestCase)
     def ...

class abc(unittest.TestCase)
    def ....

Class 'xyz' and 'abc' are separate because they have different setUp and tearDown procedures. However, the tests (def 's ...) in the testcase 'xyz' have an output. The testcase 'abc' and its various tests are dependent on the output from the testcase 'xyz'.

So my question: If the testcase xyz fails for some reason, is there a way to catch that failure and then tell class abc to not run (skip)?

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Jacob Dorman (japhezbemeye) said :
#1

I'd use a try-catch block inside of the testcase for 'xyz'. I assume you're considering a FindFailed or similar exception to be failing. In the except block, return a sentinel value (or perhaps False). Add an if statement that checks the returned value against your sentinel value, and if its False (in our example), skip the 'abc' class tests.

I may be misinterpreting something, but the way I read it that should work.

Try-Catch:
http://docs.python.org/tutorial/errors.html#handling-exceptions

Revision history for this message
Kyle VandenLangenberg (vandenk) said :
#2

Thanks for the response.

I'm a huge novice when it comes to this stuff. So let me see if I get this.

To reiterate what I'm doing in a bit more detail:

I am using the SIkuli IDE functions to do a lot of find, click, wait, click, etc... Its just easier to program what I need to do using the images (click on this button, click on this link, etc...)

So the class xyz opens one program, performs some tasks, saves some files, and its done. I use some assert exist() statements within the xyz class to check and see if certain parts of that testcase are correct; however, as you said, the exceptions that I will likely see are FindFailed exceptions and these are the ones that cause an error in the class.

The 2nd class abc then opens the files saved in class xyz and it is checking them for correctness. (XYZ is exporting file types, ABC is opening each file type in a text editor to make sure the export occurred as expected). If XYZ has an exception, the 2nd class automatically can't work because XYZ never finished. So the entire thing really falls apart.

What you are saying is that at every point where I am executing a Find (e.g. click(image)), I need to actually use a try/catch statement? Or is there a way to wrap the entire class and ask the question "If in this class xyz, at any point, if an exception (error) is returned, save a value (say FALSE), and then in the abc class, at the very beginning, add an if statement that will skip the abc class (and hopefully also print something like "Skipped class abc because of exception in xyz").

Thanks in advance for the help. Again because I am a novice detail is appreciated.

Revision history for this message
RaiMan (raimund-hocke) said :
#3

Since you seem to be relatively new to testing with Python's unittest, but the right way would be to analyze the test test results produced by the test runner - but this might be too complex for you at the moment.

So an easy way (similar to what Jacob said): just at the beginning of your script define a global variable:

testOK = false

In your first test class at the places where you know it is a success, say
testOK = true

and then in the setUp() or even already in a setup/teardown of class 1 terminate your stuff or take corrective actions.

if not testOK:
    print "makes no sense any longer"; exit()

BTW: looking at your workflow description: seems not to be the typical unittest showcase, so it might be a little bit too much effort with it. Seems to be possible with a more normal straight forward script with a main workflow and some def()'s.

Can you help with this problem?

Provide an answer of your own, or ask Kyle VandenLangenberg for more information if necessary.

To post a message you must log in.