This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Dominik V.
Recipients Dominik V.
Date 2020-12-22.23:46:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1608680811.32.0.033035519481.issue42722@roundup.psfhosted.org>
In-reply-to
Content
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__':
    unittest.main()
```

If we were calling `foo` directly we could enter post-mortem debugging via
`python -m pdb test.py`.
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:
https://stackoverflow.com/questions/4398967/python-unit-testing-automatically-running-the-debugger-when-a-test-fails
History
Date User Action Args
2020-12-22 23:46:51Dominik V.setrecipients: + Dominik V.
2020-12-22 23:46:51Dominik V.setmessageid: <1608680811.32.0.033035519481.issue42722@roundup.psfhosted.org>
2020-12-22 23:46:51Dominik V.linkissue42722 messages
2020-12-22 23:46:51Dominik V.create