[TIP] Annotated tracebacks
holger at merlinux.eu
Sun Oct 19 01:38:28 PDT 2014
On Sat, Oct 18, 2014 at 22:52 +1300, Robert Collins wrote:
> testtools just had this bug opened on it:
> Which has a few contributing issues but one in particular is that
> simple tracebacks don't give you the value of variables in parameters,
> nor of local variables in the trace.
What do you mean with "variables in parameters"?
> I'm aware of the implementation details that can make showing those
> values fraught (since __str__ and __repr__ can execute arbitrary
> code), but I thought I'd do a straw poll here and see who supports the
> idea of the traceback module itself offering to format such things
> (e.g. via a locals=False parameter to format_list and friends), which
> testtools could then backport to older pythons, and use itself to do
> In terms of addressing the implementation details, my thoughts today
> are to render the traceback once in simple mode, and then once with
> variables, and if something throws during the variable render, just
> use the simple one.
I am open to discuss what it takes to factor out or reimagine pytest's
traceback code (tested against py26-py34,pypy) so it becomes useable from
testtools. You can see it in action with:
py.test --tb=short,long,native [--full-trace] [--showlocals] somefile.py
If somefile.py contains:
i = 3
assert i == 4
While the code for the traceback code leaves things to be desired
(i wrote parts of it 8 years ago), it is quite battle tested because
it overtime incorporated tests and fixes for reported bugs.
Note that the assertion expression code showing (values in expressions)
is not strictly related to traceback manipulation and can be manipulated
separately with "--assert=rewrite|plain|reinterp"
> Robert Collins <rbtcollins at hp.com>
> Distinguished Technologist
> HP Converged Cloud
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
More information about the testing-in-python