classification
Title: unittest.py sys.exit error
Type: behavior
Components: IDLE Versions: Python 2.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: kbk Nosy List: acgetchell, georg.brandl, kbk, pupeno
Priority: Keywords:

Created on 2008-05-11 19:00 by acgetchell, last changed 2008-08-11 13:20 by pupeno.

Files
File name Uploaded Description Edit Remove
unittest.py acgetchell, 2008-05-11 19:00 Python unit testing framework
unnamed acgetchell, 2008-05-12 04:16
image001.png acgetchell, 2008-05-12 04:16
image002.png acgetchell, 2008-05-12 04:16
Messages
msg66651 (view) Author: Adam Getchell (acgetchell) Date: 2008-05-11 19:00
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
        random.shuffle(self.seq)
        self.seq.sort()
        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__':
    unittest.main()

Gives the following error:

>>> 
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK
Traceback (most recent call last):
  File "C:\Projects\Python\randomunittest.py", line 25, in <module>
    unittest.main()
  File "C:\Python25\lib\unittest.py", line 768, in __init__
    self.runTests()
  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())
msg66681 (view) Author: Georg Brandl (georg.brandl) Date: 2008-05-11 21:56
Can you elaborate how you get the printed exception? When running your
code as a script under 2.5 or trunk, I don't get such a message.
msg66707 (view) Author: Adam Getchell (acgetchell) Date: 2008-05-12 04:16
When I run randomunittest.py in IDLE, I get back the following in the Python Shell:

Type "copyright", "credits" or "license()" for more information.

    ****************************************************************

    Personal firewall software may warn about the connection IDLE

    makes to its subprocess using this computer's internal loopback

    interface.  This connection is not visible on any external

    interface and no data is sent to or received from the Internet.

    ****************************************************************

IDLE 1.2.2      ==== No Subprocess ====

>>>

Traceback (most recent call last):

  File "C:\Projects\Python\randomunittest.py", line 25, in <module>

    unittest.main()

  File "C:\Python25\lib\unittest.py", line 768, in __init__

    self.runTests()

  File "C:\Python25\lib\unittest.py", line 805, in runTests

    result = self.testRunner.run(self.test)

  File "C:\Python25\lib\unittest.py", line 705, in run

    test(result)

  File "C:\Python25\lib\unittest.py", line 437, in __call__

    return self.run(*args, **kwds)

  File "C:\Python25\lib\unittest.py", line 433, in run

    test(result)

  File "C:\Python25\lib\unittest.py", line 437, in __call__

    return self.run(*args, **kwds)

  File "C:\Python25\lib\unittest.py", line 433, in run

    test(result)

  File "C:\Python25\lib\unittest.py", line 281, in __call__

    return self.run(*args, **kwds)

  File "C:\Python25\lib\unittest.py", line 276, in run

    if ok: result.addSuccess(self)

  File "C:\Python25\lib\unittest.py", line 657, in addSuccess

    self.stream.write('.')

  File "C:\Python25\lib\idlelib\PyShell.py", line 1248, in write

    self.shell.write(s, self.tags)

  File "C:\Python25\lib\idlelib\PyShell.py", line 1237, in write

    raise KeyboardInterrupt

KeyboardInterrupt

>>>

[cid:image001.png@01C8B3AC.3F872F30]

[cid:image002.png@01C8B3AC.3F872F30]

> -----Original Message-----

> From: Georg Brandl [mailto:report@bugs.python.org]

> Sent: Sunday, May 11, 2008 2:57 PM

> To: Getchell, Adam

> Subject: [issue2821] unittest.py sys.exit error

>

>

> Georg Brandl <georg@python.org> added the comment:

>

> Can you elaborate how you get the printed exception? When running your

> code as a script under 2.5 or trunk, I don't get such a message.

>

> ----------

> nosy: +georg.brandl

>

> __________________________________

> Tracker <report@bugs.python.org>

> <http://bugs.python.org/issue2821>;

> __________________________________
msg66733 (view) Author: Georg Brandl (georg.brandl) Date: 2008-05-12 16:22
This is an IDLE problem then.
msg66748 (view) Author: Adam Getchell (acgetchell) Date: 2008-05-12 18:36
Agreed.

C:\Projects\Python>python randomunittest.py
...
----------------------------------------------------------------------
Ran 3 tests in 0.003s

OK

C:\Projects\Python>

> -----Original Message-----
> From: Georg Brandl [mailto:report@bugs.python.org]
> Sent: Monday, May 12, 2008 9:22 AM
> To: Getchell, Adam
> Subject: [issue2821] unittest.py sys.exit error
>
>
> Georg Brandl <georg@python.org> added the comment:
>
> This is an IDLE problem then.
>
> ----------
> assignee:  -> kbk
> components: +IDLE -Library (Lib)
> nosy: +kbk
>
> __________________________________
> Tracker <report@bugs.python.org>
> <http://bugs.python.org/issue2821>;
> __________________________________
msg71016 (view) Author: J. Pablo Fernández (pupeno) Date: 2008-08-11 13:20
Shouldn't this be closed now? or is there anything pending to be solved?
History
Date User Action Args
2008-08-11 13:20:42pupenosetnosy: + pupeno
messages: + msg71016
2008-05-12 18:37:07acgetchellsetmessages: + msg66748
2008-05-12 16:22:08georg.brandlsetassignee: kbk
messages: + msg66733
components: + IDLE, - Library (Lib)
nosy: + kbk
2008-05-12 04:16:33acgetchellsetfiles: + unnamed, image001.png, image002.png
messages: + msg66707
2008-05-11 21:56:56georg.brandlsetnosy: + georg.brandl
messages: + msg66681
2008-05-11 19:00:57acgetchellcreate