Re: [Pyunit-interest] Help!
Brought to you by:
purcell
From: Steve P. <pu...@us...> - 2006-05-29 12:34:37
|
Hi Peter, The function 'unittest.main()' is the top-level function that turns a python file into a standalone runnable test program. It uses sys.exit () to indicate whether the tests passed or not. What you see here is the result of running that function inside an interactive interpreter, which is intercepting the 'SystemExit' that is thrown by sys.exit(). If you don't care about the exit code, you can just wrap 'unittest.main()' in a try: except SystemExit: block. Hope that helps, -Steve On 29 May 2006, at 00:04, Peter Olsen wrote: > I am completely befuddled. > > > I run this program > > ---------- > > def matrixSize(matrix): > return (len(matrix),len(matrix[0])) > > if __name__ == "__main__": > > import unittest > > print "Unit test code." > > # class MatrixUtilsTest(unittest.TestCase): > # def setUp(self): > # self.a=[[1,2],[3,4]] > # self.b = [[2,4],[6,8]] > # self.c = [[3,6],[9,12]] > # self.d = [[2,8],[18,32]] > # print self.a > > class MatrixSizeTest(unittest.TestCase): > def runTest(self): > self.a = [[1,2],[3,4]] > self.assertEqual(matrixSize(self.a),(2,2)) > > > # class MatrixSumTest(MatrixUtilsTest): > # def testSum(self): > # self.failUnless(matrixSum(self.a, self.b) == [[3,6], > [9,12]], > # "sum incorrect") > > > t = MatrixSizeTest() > print t > unittest.main() > > ---------- > > and get this result > > ---------- > > >>> ================================ RESTART > ================================ > >>> > Unit test code. > runTest (__main__.MatrixSizeTest) > . > ---------------------------------------------------------------------- > Ran 1 test in 0.024s > > OK > > Traceback (most recent call last): > File "/Users/pcolsen/D.Sources/Nash_Compact_Numerical_Methods/ > testTest.py", line 32, in -toplevel- > unittest.main() > File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ > python2.4/unittest.py", line 759, in __init__ > self.runTests() > File "/Library/Frameworks/Python.framework/Versions/2.4/lib/ > python2.4/unittest.py", line 797, in runTests > sys.exit(not result.wasSuccessful()) > SystemExit: False > >>> > > ---------- > > I'm using MacPython 2.4 running on OS-X > > System Version: Mac OS X 10.4.6 (8I127) > Kernel Version: Darwin 8.6.0 > > > > > > ------------------------------------------------------- > All the advantages of Linux Managed Hosting--Without the Cost and > Risk! > Fully trained technicians. The highest number of Red Hat > certifications in > the hosting industry. Fanatical Support. Click to learn more > http://sel.as-us.falkag.net/sel? > cmd=lnk&kid=107521&bid=248729&dat=121642 > _______________________________________________ > Pyunit-interest mailing list > Pyu...@li... > https://lists.sourceforge.net/lists/listinfo/pyunit-interest |