unittest execution hanging when the image is not found

Asked by piravel

I'm launching a simple Python unittest in commandline.
The test contains an assert which is failing (this is what I want just to see the behavior when the test fails).

When the asertion fails, the execution of the test just hangs and never ends...

I launch the test with the following command :
java -jar sikuli-script.jar TESTS\testCalculatrice.sikuli

and here is the script :

import sys
import unittest
setAutoWaitTimeout(5000)

class MyTests(unittest.TestCase):

  def setUp(self):
    openApp("C:/WINDOWS/system32/calc.exe")
    wait(5)

  def tearDown(self):
    closeApp("Calculatrice")

  def test_addition(self):
    click("2.png")
    click("plus.png")
    click("2.png")
    click("equal.png")
    assert (exists("image_which_does_not_exist.png"))

suite = unittest.TestLoader().loadTestsFromTestCase(MyTests)
unittest.TextTestRunner(verbosity=2).run(suite)

The test works just fine when the assert is ok, but it is blocked when the assert fails... And the console is showing no error. The last line in the console is the las CLICK instruction.

Am'I missing something, is there something to do to let the execution continue after the failed assertion ?
Any help is appreciated.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

When I do this simple scenario on Mac or Win7

import unittest

class MyTests(unittest.TestCase):

 def setUp(self):
   print "setup"

 def tearDown(self):
   print "teardown"

 def test1(self):
   print "test"
# assert (False)
   assert (True)

suite = unittest.TestLoader().loadTestsFromTestCase(MyTests)
unittest.TextTestRunner().run(suite)
print "testing is over"

------------- I get the following output:

--- in case assert(True)
setup
test
teardown
.
----------------------------------------------------------------------
Ran 1 test in 0.001s

OK
testing is over

--- in case assert(False)
setup
test
teardown

F
======================================================================
FAIL: test1 (__main__.MyTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/rhocke/testtest.sikuli/testtest.py", line 13, in test1
    assert (False)
AssertionError

----------------------------------------------------------------------
Ran 1 test in 0.020s

FAILED (failures=1)
testing is over

So in both cases unittest does what it should (setUp, perform all def's contained in the TestCase that start with test..., tearDown). And then it runs any script statements that come after the test run.

So what is your problem/question?

Revision history for this message
piravel (pkeravel) said :
#2

Interesting : when I add a timetout for the assert exists, the script ends correctly with the failed assertion.

I replaced the line :
assert (exists("image_which_does_not_exist.png"))

by the line :
assert (exists("image_which_does_not_exist.png", 5))

It looks like the exists function is searching for an infinite time unless limited with a timeout...
Is that the normal behavior ?

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

Uuups, sorry for being such blind --- LOL ---

In the beginning of your script you set

SetAutoWaitTimeout(5000)

which sets it to 5000 seconds --- a long time ;-)

Where did you get the script? it is based on Sikuli release 0.9x, where the timout parameter counted in miliseconds.

So it is clear what happens:

exits(image) waits as long as AutoWaitTimeout is set (1 1/2 hour in your case)

exists(image, 5) waits only 5 seconds.

again double LOL

Revision history for this message
piravel (pkeravel) said :
#4

Thanks RaiMan, that solved my question.

Revision history for this message
piravel (pkeravel) said :
#5

I just found about it in the same time...

Oups... ok, my mistake, I just copy/paste this instruction without really thinking about it. ARGGGGGHH!

Thanks for your help Raiman

Revision history for this message
piravel (pkeravel) said :
#6

I get the model script from this page:
https://answers.launchpad.net/sikuli/+question/100436

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

thanks, I have edited the post and placed a warning - it started with 0.9x and ended with 0.10.1 ;-)