Author Dominik V.
Recipients Dominik V.
Date 2020-12-22.23:46:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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:
Date User Action Args
2020-12-22 23:46:51Dominik V.setrecipients: + Dominik V.
2020-12-22 23:46:51Dominik V.setmessageid: <>
2020-12-22 23:46:51Dominik V.linkissue42722 messages
2020-12-22 23:46:51Dominik V.create