classification
Title: unittest errors can't show locals
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, rbcollins
Priority: normal Keywords:

Created on 2014-11-25 02:06 by rbcollins, last changed 2015-03-16 03:19 by rbcollins. This issue is now closed.

Messages (4)
msg231629 - (view) Author: Robert Collins (rbcollins) * (Python committer) Date: 2014-11-25 02:06
From https://github.com/testing-cabal/testtools/issues/111 - any code that is data dependent can be hard to diagnose from a backtrace alone. Many unittest and server environments address this by doing custom tracebacks that include locals.

To address this in unittest, we need to add a similar capacity to traceback, and then use it from unittest (as we can't just depend on a module from PyPI in the stdlib). This issue is for the unittest part of it. For the traceback dependency see http://bugs.python.org/issue22936 .
msg231735 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2014-11-26 23:56
Note that IIRC py.test (a 3rd party module) will show you additional information in the traceback. SO it is definitely possible.
msg231737 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2014-11-27 00:03
Sorry, I missed the part where you said "we can't depend on PyPI".

There already is something in the stdlib that may be close enough to what you're looking for -- checkout cgitb.py.  The following might even work:

import cgitb
cgitb.enable(format='text')

That code is very old and primarily meant for CGI scripts (that shows how old it is!) but it still works.
msg238179 - (view) Author: Robert Collins (rbcollins) * (Python committer) Date: 2015-03-16 03:19
Fixed (patch referenced 22936)
History
Date User Action Args
2015-03-16 03:19:32rbcollinssetstatus: open -> closed
resolution: fixed
messages: + msg238179
2014-11-27 00:03:13gvanrossumsetmessages: + msg231737
2014-11-26 23:56:11gvanrossumsetnosy: + gvanrossum
messages: + msg231735
2014-11-25 02:06:22rbcollinscreate