Skip to content

Commit a4909a8

Browse files
committed
Update docs for new unittest debug modes
1 parent 5d89a01 commit a4909a8

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

Doc/library/unittest.rst

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,25 @@ Command-line options
220220

221221
See `Signal Handling`_ for the functions that provide this functionality.
222222

223+
.. cmdoption:: --debug
224+
225+
On test fail or error the test run terminates immediately with original
226+
exception - similar to normal script execution. Useful for seamless external
227+
post-mortem handling.
228+
229+
.. cmdoption:: --pdb
230+
231+
Runs ``pdb.post_mortem()`` upon each error. Short for ``--pm=pdb``
232+
233+
.. cmdoption:: --pm
234+
235+
Run custom post-mortem debugger (module or class) upon each error.
236+
Examples: ``--pm=pywin.debugger``, ``--pm=IPython.terminal.debugger.Pdb``
237+
238+
.. cmdoption:: --trace
239+
240+
Break at the beginning of each test using :mod:`pdb` or the debugger set by ``--pm``
241+
223242
.. cmdoption:: -f, --failfast
224243

225244
Stop the test run on the first error or failure.
@@ -253,6 +272,9 @@ Command-line options
253272
.. versionadded:: 3.7
254273
The command-line option ``-k``.
255274

275+
.. versionadded:: 3.12
276+
The command-line options ``--debug``, ``--pdb`` and ``--pm``.
277+
256278
The command line can also be used for test discovery, for running all of the
257279
tests in a project or just a subset.
258280

@@ -2228,7 +2250,8 @@ Loading and running tests
22282250

22292251
.. function:: main(module='__main__', defaultTest=None, argv=None, testRunner=None, \
22302252
testLoader=unittest.defaultTestLoader, exit=True, verbosity=1, \
2231-
failfast=None, catchbreak=None, buffer=None, warnings=None)
2253+
failfast=None, catchbreak=None, buffer=None, warnings=None, \
2254+
debug=False)
22322255

22332256
A command-line program that loads a set of tests from *module* and runs them;
22342257
this is primarily for making test modules conveniently executable.
@@ -2279,6 +2302,12 @@ Loading and running tests
22792302
Calling ``main`` actually returns an instance of the ``TestProgram`` class.
22802303
This stores the result of the tests run as the ``result`` attribute.
22812304

2305+
When *debug* is ``True`` (corresponding to ``--debug``) execution terminates
2306+
with original exception upon the first error. When *debug* is the name of a
2307+
debugger module or class - for example ":mod:`pdb`" - then post-mortem debugging is
2308+
run upon each error.
2309+
2310+
22822311
.. versionchanged:: 3.1
22832312
The *exit* parameter was added.
22842313

@@ -2290,6 +2319,9 @@ Loading and running tests
22902319
The *defaultTest* parameter was changed to also accept an iterable of
22912320
test names.
22922321

2322+
.. versionchanged:: 3.12
2323+
The *debug* parameter was added.
2324+
22932325

22942326
load_tests Protocol
22952327
###################
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added ``--debug``, ``--pdb``, ``--pm``, ``--trace`` command line options to :mod:`unittest`.

0 commit comments

Comments
 (0)