Issue42722
Created on 2020-12-22 23:46 by Dominik V., last changed 2021-05-19 19:09 by ned.deily.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 23900 | open | Dominik V., 2020-12-22 23:52 | |
| Messages (3) | |||
|---|---|---|---|
| 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__':
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
|
|||
| 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. |
|||
| msg393961 - (view) | Author: Andrei Kulakov (andrei.avk) * ![]() |
Date: 2021-05-19 18:25 | |
This is a duplicate of https://bugs.python.org/issue18765, which already has some discussion going for a few years, so please follow up there. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2021-05-19 19:09:06 | ned.deily | set | nosy:
+ gregory.p.smith |
| 2021-05-19 18:25:08 | andrei.avk | set | nosy:
+ andrei.avk messages: + msg393961 |
| 2021-04-13 10:19:57 | remi.lapeyre | set | nosy:
+ remi.lapeyre |
| 2021-01-22 13:23:10 | Dominik V. | set | messages:
+ msg385498 versions: + Python 3.10 |
| 2020-12-22 23:52:55 | Dominik V. | set | keywords:
+ patch stage: patch review pull_requests: + pull_request22755 |
| 2020-12-22 23:46:51 | Dominik V. | create | |
