Title: Add --debug command line option to unittest to enable post-mortem debugging
Type: enhancement Stage: patch review
Components: Versions: Python 3.10
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Dominik V.
Priority: normal Keywords: patch

Created on 2020-12-22 23:46 by Dominik V., last changed 2021-01-22 13:23 by Dominik V..

Pull Requests
URL Status Linked Edit
PR 23900 open Dominik V., 2020-12-22 23:52
Messages (2)
msg383624 - (view) Author: Dominik Vilsmeier (Dominik V.) * Date: 2020-12-22 23:46
Currently there is no option to use post-mortem debugging via `pdb`
on a `unittest` test case which fails due to an exception being leaked.

Consider the following example:

import unittest

def foo():
    for x in [1, 2, 'oops', 4]:
        print(x + 100)

class TestFoo(unittest.TestCase):
    def test_foo(self):
        self.assertIs(foo(), None)

if __name__ == '__main__':

If we were calling `foo` directly we could enter post-mortem debugging via
`python -m pdb`.
However since `foo` is wrapped in a test case, `unittest` eats the
exception and thus prevents post-mortem debugging.

So I propose adding a
command-line option `--debug` to unittest for running
test cases in debug mode so that post-mortem debugging can be used.

I see that some third-party distributions enable this, but since both
`unittest` and `pdb` are part of the standard library, it would
be nice if they played well together.
Plus the required methods are already in place (`TestCase.debug`
and `TestSuite.debug`).

There is also a popular StackOverflow question on this topic:
msg385498 - (view) Author: Dominik Vilsmeier (Dominik V.) * Date: 2021-01-22 13:23
Is anybody interested in reviewing the PR? It seems like a useful enhancement to me.
Date User Action Args
2021-01-22 13:23:10Dominik V.setmessages: + msg385498
versions: + Python 3.10
2020-12-22 23:52:55Dominik V.setkeywords: + patch
stage: patch review
pull_requests: + pull_request22755
2020-12-22 23:46:51Dominik V.create