Python unittest and reporting exit status back to Windows shell

Asked by Chris Cera

I'm using the Python unittest implementation, and trying to get an exit status to "bubble-up" to the Windows shell. I basically want the basic functionality provided by unittest.main(), but Sikuli uses TextTestRunner and I cannot figure out how to get the

The commands I'm running are the following:

$ java -jar "c:\Program Files\Sikuli X\sikuli-script.jar" PrototypeRuns.sikuli
$ echo %ERRORLEVEL%

The ERRORLEVEL is always 0. I've tried adding a sys.exit() and passing in the number of errors, but this causes Sikuli to report "[error] Can't run this Sikuli script: PrototypeRuns.sikuli"

My code is very small/basic, and I think I'm just missing something because I'm a n00b:

from sikuli import *
import unittest

class UnitTestA(unittest.TestCase):

  def setUp(self):
    return None

  def tearDown(self):
    return None

  def testAlwaysFails(self):
    assert(False)

if __name__ == '__main__':
  suite = unittest.TestLoader().loadTestsFromTestCase(UnitTestA)
  runner = unittest.TextTestRunner(verbosity=2)
  result = runner.run(suite)

  # combines the number of errors and failures
  status = len(result.errors) + len(result.failures)
  sys.exit(status)

Any help is greatly appreciated! Thanks -Chris

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
RaiMan (raimund-hocke) said :
#1

already tried
exit(status)

Revision history for this message
Chris Cera (cera-h) said :
#2

RaiMan,

I'm not sure if I understand your post correctly.

I tried replacing sys.exit(status) with exit(status) and I still get the same problem where it gets the "[error] Can't run this Sikuli script: PrototypeRuns.sikuli". However, I noticed that despite this error, the %ERRORLEVEL% actually appears to be correct whereas if I exit with 0, it will return back 0 to the command-line. This doesn't seem like a graceful solution since it says "[error]" in the message, but I suppose it could work. Do you know of any alternatives?

Thank you very much for your time! -Chris

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

Just forget this error message - it is a bug ;-)
... and happens, when running scripts this way, though the script is run.

You might try the "official" way, to run scripts from command line using Sikuli-IDE.bat or Sikuli-IDE-w.bat, which even allows to hand over command line parameters to the script (see docs).

Can you help with this problem?

Provide an answer of your own, or ask Chris Cera for more information if necessary.

To post a message you must log in.