Adds an exit parameter to unittest.main(). If False main no longer
calls sys.exit.

Closes issue 3379.

Michael Foord
diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst
index 16da21c..065832d 100644
--- a/Doc/library/unittest.rst
+++ b/Doc/library/unittest.rst
@@ -1364,7 +1364,7 @@
       subclasses to provide a custom ``TestResult``.
 
 
-.. function:: main([module[, defaultTest[, argv[, testRunner[, testLoader]]]]])
+.. function:: main([module[, defaultTest[, argv[, testRunner[, testLoader[, exit]]]]]])
 
    A command-line program that runs a set of tests; this is primarily for making
    test modules conveniently executable.  The simplest use for this function is to
@@ -1374,4 +1374,18 @@
           unittest.main()
 
    The *testRunner* argument can either be a test runner class or an already
-   created instance of it.
+   created instance of it. By default ``main`` calls :func:`sys.exit` with
+   an exit code indicating success or failure of the tests run.
+
+   ``main`` supports being used from the interactive interpreter by passing in the
+   argument ``exit=False``. This displays the result on standard output without
+   calling :func:`sys.exit`::
+
+      >>> from unittest import main
+      >>> main(module='test_module', exit=False)
+
+   Calling ``main`` actually returns an instance of the ``TestProgram`` class.
+   This stores the result of the tests run as the ``result`` attribute.
+
+   .. versionchanged:: 2.7
+      The ``exit`` parameter was added.
diff --git a/Doc/whatsnew/2.7.rst b/Doc/whatsnew/2.7.rst
index 24d4549..92fedb7 100644
--- a/Doc/whatsnew/2.7.rst
+++ b/Doc/whatsnew/2.7.rst
@@ -477,6 +477,10 @@
     to provide additional information about why the two objects are
     matching, much as the new sequence comparison methods do.
 
+  :func:`unittest.main` now takes an optional ``exit`` argument.
+  If False ``main`` doesn't call :func:`sys.exit` allowing it to
+  be used from the interactive interpreter. :issue:`3379`.
+
 * The :func:`is_zipfile` function in the :mod:`zipfile` module will now
   accept a file object, in addition to the path names accepted in earlier
   versions.  (Contributed by Gabriel Genellina; :issue:`4756`.)