<p>No matter what I do sys.exit() is called by unittest, even the most trivial examples.  I can't tell if my install is messed up or what is going on.</p>

<pre><code>IDLE 1.2.2      ==== No Subprocess ====
&gt;&gt;&gt; import unittest
&gt;&gt;&gt; 
&gt;&gt;&gt; class Test(unittest.TestCase):
        def testA(self):
            a = 1
            self.assertEqual(a,1)

&gt;&gt;&gt; unittest.main()
option -n not recognized
Usage: idle.pyw [options] [test] [...]

Options:
  -h, --help       Show this message
  -v, --verbose    Verbose output
  -q, --quiet      Minimal output

 Examples:
   idle.pyw                               - run default set of tests
   idle.pyw MyTestSuite                   - run suite 'MyTestSuite'
   idle.pyw MyTestCase.testSomething      - run MyTestCase.testSomething
   idle.pyw MyTestCase                    - run all 'test*' test methods
                                           in MyTestCase

Traceback (most recent call last):
  File "&lt;pyshell#7&gt;", line 1, in &lt;module&gt;
    unittest.main()
  File "E:\Python25\lib\unittest.py", line 767, in __init__
    self.parseArgs(argv)
  File "E:\Python25\lib\unittest.py", line 796, in parseArgs
    self.usageExit(msg)
  File "E:\Python25\lib\unittest.py", line 773, in usageExit
    sys.exit(2)
SystemExit: 2
&gt;&gt;&gt; 
</code></pre>

[{'answer_id': 79826, 'author': 'Allen', 'author_id': 6043, 'author_profile': 'https://Stackoverflow.com/users/6043', 'pm_score': 3, 'selected': False, 'text': "<p>Don't try to run <code>unittest.main()</code> from IDLE. It's trying to access <code>sys.argv</code>, and it's getting the args that IDLE was started with. Either run your tests in a different way from IDLE, or call <code>unittest.main()</code> in its own Python process.</p>\n"}, {'answer_id': 79833, 'author': 'Joe Skora', 'author_id': 14057, 'author_profile': 'https://Stackoverflow.com/users/14057', 'pm_score': 5, 'selected': True, 'text': '<p>Your example is exiting on my install too.  I can make it execute the tests and stay within Python by changing</p>\n\n<pre><code>unittest.main()\n</code></pre>\n\n<p>to</p>\n\n<pre><code>unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromTestCase(Test))\n</code></pre>\n\n<p>More information is available <a href="http://docs.python.org/library/unittest.html#basic-example" rel="noreferrer">here</a> in the Python Library Reference.</p>\n'}, {'answer_id': 79932, 'author': 'John Millikin', 'author_id': 3560, 'author_profile': 'https://Stackoverflow.com/users/3560', 'pm_score': 3, 'selected': False, 'text': '<p>Pop open the source code to <code>unittest.py</code>. <code>unittest.main()</code> is hard-coded to call <code>sys.exit()</code> after running all tests. Use <code>TextTestRunner</code> to run test suites from the prompt.</p>\n'}, {'answer_id': 407950, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': "<pre><code>try:\n    sys.exit()\nexcept SystemExit:\n    print('Simple as that, but you should really use a TestRunner instead')\n</code></pre>\n"}, {'answer_id': 3215505, 'author': 'dmeister', 'author_id': 4194, 'author_profile': 'https://Stackoverflow.com/users/4194', 'pm_score': 5, 'selected': False, 'text': '<p>In new Python 2.7 release, <a href="http://docs.python.org/library/unittest.html#unittest.main" rel="noreferrer">unittest.main()</a> has a new argument.</p>\n\n<p>If \'exit\' is set to <code>False</code>, <code>sys.exit()</code> is not called during the execution of <code>unittest.main()</code>.</p>\n'}, {'answer_id': 21262077, 'author': 'Russia Must Remove Putin', 'author_id': 541136, 'author_profile': 'https://Stackoverflow.com/users/541136', 'pm_score': 3, 'selected': False, 'text': "<p>It's nice to be able to demonstrate that your tests work when first trying out the unittest module, and to know that you won't exit your Python shell. However, these solutions are version dependent.</p>\n\n<h2>Python 2.6</h2>\n\n<p>I'm using Python 2.6 at work, <code>import</code>ing <code>unittest2 as unittest</code> (which is the <code>unittest</code> module supposedly found in Python 2.7). </p>\n\n<p>The <code>unittest.main(exit=False)</code> doesn't work in Python 2.6's unittest2, while JoeSkora's solution does, and to reiterate it:</p>\n\n<pre><code>unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromTestCase(Test))\n</code></pre>\n\n<p>To break this down into its components and default arguments, with correct semantic names for the various composed objects:</p>\n\n<pre><code>import sys # sys.stderr is used in below default args\n\ntest_loader = unittest.TestLoader()\nloaded_test_suite = test_loader.loadTestsFromTestCase(Test)\n                                           # Default args:\ntext_test_runner = unittest.TextTestRunner(stream=sys.stderr,\n                                           descriptions=True, \n                                           verbosity=1)\ntext_test_runner.run(loaded_test_suite)\n</code></pre>\n\n<h2>Python 2.7 and 3</h2>\n\n<p>In Python 2.7 and higher, the following should work.</p>\n\n<pre><code>unittest.main(exit=False)\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/79754', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3176/']