[New-bugs-announce] [issue2821] unittest.py sys.exit error

Adam Getchell report at bugs.python.org
Sun May 11 21:00:57 CEST 2008

New submission from Adam Getchell <acgetchell at ucdavis.edu>:

Picking the canonical example of unit test:

import random
import unittest

class TestSequenceFunctions(unittest.TestCase):
    def setUp(self):
        self.seq = range(10)

    def testshuffle(self):
        # make sure the shuffled sequence does not lose any elements
        self.assertEqual(self.seq, range(10))

    def testchoice(self):
        element = random.choice(self.seq)
        self.assert_(element in self.seq)

    def testsample(self):
        self.assertRaises(ValueError, random.sample, self.seq, 20)
        for element in random.sample(self.seq, 5):
            self.assert_(element in self.seq)

if __name__ == '__main__':

Gives the following error:

Ran 3 tests in 0.003s

Traceback (most recent call last):
  File "C:\Projects\Python\randomunittest.py", line 25, in <module>
  File "C:\Python25\lib\unittest.py", line 768, in __init__
  File "C:\Python25\lib\unittest.py", line 806, in runTests
    sys.exit(not result.wasSuccessful())
SystemExit: False

The error lies in the following code snippet:

    def runTests(self):
        if self.testRunner is None:
            self.testRunner = TextTestRunner(verbosity=self.verbosity)
        result = self.testRunner.run(self.test)
        sys.exit(not result.wasSuccessful())

components: Library (Lib)
files: unittest.py
messages: 66651
nosy: acgetchell
severity: normal
status: open
title: unittest.py sys.exit error
type: behavior
versions: Python 2.5
Added file: http://bugs.python.org/file10289/unittest.py

Tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list