New submission from Dominik V. <[email protected]>:
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
----------
messages: 383624
nosy: Dominik V.
priority: normal
severity: normal
status: open
title: Add --debug command line option to unittest to enable post-mortem
debugging
type: enhancement
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue42722>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com