Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 681511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:29:30+00:00 2026-05-14T01:29:30+00:00

Is there a way, within IDLE, to run the PyUnit (unittest module) unit tests

  • 0

Is there a way, within IDLE, to run the PyUnit (unittest module) unit tests directly?

I ask because I have a short test module and when I run it with python mymodule.py from the Cygwin shell I get all tests passed, but when I use Run->Run Module from IDLE the tests pass but then I get an exception (SystemExit: False).

For example, here is a sample test module to reproduce this:

#!/usr/bin/python

import unittest

class fooTests(unittest.TestCase):

    def setUp(self):
        self.foo = "bar"

    def testDummyTest(self):
        self.assertTrue(True)

    def testDummyTestTwo(self):
        self.assertEquals("foo", "foo")


    def tearDown(self):
        self.foo = None

if __name__ == '__main__':
    unittest.main()

When I run this from the Cygwin shell with python fooTests.py it produces:

$ python fooTests.py
..
----------------------------------------------------------------------
Ran 2 tests in 0.000s

OK

But when I’m editing fooTests.py within IDLE and I do Run -> Run Module, the new Python Shell spawned by IDLE produces:

>>> ================================ RESTART ================================
>>> 
..
----------------------------------------------------------------------
Ran 2 tests in 0.031s

OK

Traceback (most recent call last):
  File "C:\Some\path\info\I\shortened\fooTests.py", line 20, in <module>
    unittest.main()
  File "C:\Python26\lib\unittest.py", line 817, in __init__
    self.runTests()
  File "C:\Python26\lib\unittest.py", line 865, in runTests
    sys.exit(not result.wasSuccessful())
SystemExit: False
>>> 

What am I doing wrong, to produce this traceback, and especially how can I fix it so that I can just do Run->Run Module (or F5) within IDLE to run the unit tests quickly?

(This surely must be a simple question, but my quick attempts to figure it out have proven fruitless.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:29:30+00:00Added an answer on May 14, 2026 at 1:29 am

    No one answered (I find that if there aren’t any answers in the first few minutes, the likelihood of an answer goes down significantly :), so I kept researching this myself.

    Not sure if this is the most elegant solution or not, but changing:

    if __name__ == '__main__':
        unittest.main()
    

    to

    if __name__ == '__main__':
        try: unittest.main()
        except SystemExit: pass
    

    seemed to do the trick.

    I guess the problem is that (according to http://coding.derkeiler.com/Archive/Python/comp.lang.python/2003-11/0239.html) the unittest module finishes by calling sys.exit which is apparently problematic for IDLE since it wants to keep the Python shell running, whereas it’s not a problem when you run it from the command line, which expects to dump you back to your already-running command line anyway.

    I don’t know if this solution, catching the SystemExit event and ignoring it, is problematic at all, but it seems to work for the all-tests-pass and some-tests-fail cases I checked.

    Also: see this StackOverFlow Post: What code can I use to check if Python is running in IDLE? , which provides a test to see whether the program is being run from within IDLE or not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way within an RSpec tests, by convention or code, to have
Is there a way to specify the color a text is printed within Idle
Is there any way within Visual Studio 2010 to have different windows and panes
Is there any way within the iOS SDK for an app to delete itself?
I am curious if there is a way from within a WebView when a
Is there any way to completely disable Siri within the app? I am not
Is there a way to pass results generated within a PHP page (called into
Is there a way to password protect SAS CODE within SAS? Or, if not,
Is there a way to uncheck/check a checkbox within a webpage that is loaded
Is there a way to find the weeknumber within the year using PHP?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.