Traceback inspector

Simple traceback introspection. Used to add additional information to AssertionErrors in tests, so that failure messages may be more informative.

class nose.inspector.Expander(locals, globals)

Simple expression expander. Uses tokenize to find the names and expands any that can be looked up in the frame.

nose.inspector.find_inspectable_lines(lines, pos)

Find lines in home that are inspectable.

Walk back from the err line up to 3 lines, but don’t walk back over changes in indent level.

Walk forward up to 3 lines, counting separated lines as 1. Don’t walk over changes in indent level (unless part of an extended line)


Inspect a traceback and its frame, returning source for the expression where the exception was raised, with simple variable replacement performed and the line on which the exception was raised marked with ‘>>’

nose.inspector.tbsource(tb, context=6)

Get source from a traceback object.

A tuple of two things is returned: a list of lines of context from the source code, and the index of the current line within that list. The optional second argument specifies the number of lines of context to return, which are centered around the current line.


This is adapted from in the python 2.4 standard library, since a bug in the 2.3 version of inspect prevents it from correctly locating source lines in a traceback frame.