summaryrefslogtreecommitdiffstats
path: root/Doc/library/unittest.rst
diff options
context:
space:
mode:
authorMichael Foord <fuzzyman@voidspace.org.uk>2009-05-02 11:43:06 (GMT)
committerMichael Foord <fuzzyman@voidspace.org.uk>2009-05-02 11:43:06 (GMT)
commit829f6b80529bcf66bf52bb9b301bf718118b8316 (patch)
tree7850c9f8dda5c01911fb32083f97b05f529e36e5 /Doc/library/unittest.rst
parent27f204dc297945378f72536e63936bf3bb995fdf (diff)
downloadcpython-829f6b80529bcf66bf52bb9b301bf718118b8316.zip
cpython-829f6b80529bcf66bf52bb9b301bf718118b8316.tar.gz
cpython-829f6b80529bcf66bf52bb9b301bf718118b8316.tar.bz2
Adds an exit parameter to unittest.main(). If False main no longer
calls sys.exit. Closes issue 3379. Michael Foord
Diffstat (limited to 'Doc/library/unittest.rst')
-rw-r--r--Doc/library/unittest.rst18
1 files changed, 16 insertions, 2 deletions
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 @@ Loading and running tests
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 @@ Loading and running tests
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.