In case someone is interested, I created a corresponding pull request here: 
https://github.com/python/cpython/pull/23900
It's a lightweight change since the relevant methods `TestCase.debug` and 
`TestSuite.debug` were already in place. The docstring of these methods makes 
it clear that this is what they were intended to be used for:

"Run the test without collecting the result. This allows exceptions raised by 
the test to be propagated to the caller, and can be used to support running 
tests under a debugger."

Dominik Vilsmeier wrote:
> 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. --failfast doesn't help,
> the exception is still swallowed.
> Since I am not aware of a solution that enables post-mortem debugging in such 
> a case
> (without modifying the test scripts, please correct me if one exists), I 
> propose adding a
> command-line option to unittest for running
> test cases in debug mode so that post-mortem debugging can be used.
> P.S.: There is also this SO
> question on a similar topic.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/NXFAAECYVGHB6O35SJAVNVTNVKIO5KOU/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to