2

My goal is to execute a python script (that executs some unittests) via a small *.bat script. The *.bat script should also receive the exit status of the python script. But it seems that the exit status of the *.py file is not transmitted correctly.

My testit.py:

execute_some_unittests()
   ...
   if success:
       sys.exit(1) 
   else:
       sys.exit(2)
   # End of the script

My test.bat:

python C:\testit.py
echo %ERRORLEVEL%

Depanding on the unittests I run in execute_some_unittests(), running test.bat results in 1, 2 or 0!!! I'm absolutly sure that the code reaches the sys.exit(1) (because i log everything) but nevertheless (depending on what unittests get tested) it goes wrong.

My guess is that executing the unittests is setting some flags which will be merged with the exit code and produce a unix like 16 bit exit code (instead of 8) and that the cmd is somwhat truncating my exit code...

Remarks:

  • The code above is not inside a try, except block
  • Replacing the sys.exit(1) with os._exit(1) does not help

I'm working since 2 days at this problem and will be gratefull for every idea...

I'm using Win7, python 2.6, modules: unittest, doctest, sys, os

Update: was asked for a full working example:

test.py:

import unittest
from scipy.interpolate import interp1d
class Test(unittest.TestCase):
    def test_basic(self):
        self.failUnlessEqual(1, 1)
if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(Test)
    unittest.TextTestRunner(verbosity=2).run(suite)
    import sys
    sys.exit(42)

test.bat:

python C:\test.py
echo %ERRORLEVEL%

Result: error level 0 (whithout import scipy.interpolate it would be 42, but scipy is not the only module producing this problem)

2
  • 1
    Are you using the unittest module at all? Commented Jan 16, 2013 at 9:00
  • Can you provide a small complete script to reproduce this? I suspect there is something wrong in the code you are not showing us. Commented Jan 16, 2013 at 9:00

1 Answer 1

1

This is a known error in the scipy module. See Issue "import scipy.sparse.sparsetools causes consistent exit code 0".

This issue seems still being open...

Sign up to request clarification or add additional context in comments.

1 Comment

THANKS a lot, it is indeed a scipy problem and import scipy.weave does fix it (but it's a realy ugly workaround)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.