This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: IDLE: unittest.py sys.exit error
Type: behavior Stage:
Components: IDLE Versions: Python 2.5
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: kbk Nosy List: acgetchell, georg.brandl, kbk, mfitz, michael.foord, pupeno
Priority: normal Keywords:

Created on 2008-05-11 19:00 by acgetchell, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
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 (8)
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) * (Python committer) 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) * (Python committer) 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?
msg85561 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2009-04-05 20:26
IDLE catches the SystemExit function raised by TestProgram().runTests()
and prints the traceback. Not a bug in unittest.
msg93494 - (view) Author: Mark Fitzgerald (mfitz) Date: 2009-10-03 14:48
Agreed that this is clearly not a bug.  One way to get the desired
behavior from IDLE is to move up to Python 2.7a0+ or Python 3.1.1+,
where the 'exit' parameter of unittest.main(), which when set to False,
disables the sys.exit() call.

Alternatively, in 2.5, just create your own TextTestRunner, as described
in the 2.5.2 docs:

suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions)
unittest.TextTestRunner(verbosity=2).run(suite)
History
Date User Action Args
2022-04-11 14:56:34adminsetgithub: 47070
2021-09-27 16:59:57terry.reedysettitle: unittest.py sys.exit error -> IDLE: unittest.py sys.exit error
2009-10-03 14:48:18mfitzsetnosy: + mfitz
messages: + msg93494
2009-04-05 20:26:53michael.foordsetstatus: open -> closed

nosy: + michael.foord
messages: + msg85561

resolution: works for me
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