def _printTraceback(self, test, err): """Print a nicely formatted traceback. :arg err: exc_info()-style traceback triple :arg test: the test that precipitated this call """ # Don't bind third item to a local var; that can create # circular refs which are expensive to collect. See the # sys.exc_info() docs. exception_type, exception_value = err[:2] extracted_tb = extract_relevant_tb( err[2], exception_type, exception_type is test.failureException) test_frame_index = index_of_test_frame(extracted_tb, exception_type, exception_value, test) if test_frame_index: # We have a good guess at which frame is the test, so # trim everything until that. We don't care to see test # framework frames. extracted_tb = extracted_tb[test_frame_index:] with self.bar.dodging(): self.stream.write(''.join( format_traceback(extracted_tb, exception_type, exception_value, self._cwd, self._term, self._options.function_color, self._options.dim_color, self._options.editor)))
def _printError(self, kind, err, test, isFailure=True): """Output a human-readable error report to the stream. kind -- the (string) type of incident the precipitated this call err -- exc_info()-style traceback triple test -- the test that precipitated this call """ if isFailure or self._options.show_advisories: writeln = self.stream.writeln write = self.stream.write with self.bar.dodging(): writeln('\n' + (self._term.bold if isFailure else '') + '%s: %s' % (kind, nose_selector(test)) + (self._term.normal if isFailure else '')) # end bold if isFailure: # Then show traceback # Don't bind third item to a local var; that can create # circular refs which are expensive to collect. See the # sys.exc_info() docs. exception_type, exception_value = err[:2] extracted_tb = extract_relevant_tb( err[2], exception_type, exception_type is test.failureException) test_frame_index = index_of_test_frame( extracted_tb, exception_type, exception_value, test) if test_frame_index: # We have a good guess at which frame is the test, so # trim everything until that. We don't care to see test # framework frames. extracted_tb = extracted_tb[test_frame_index:] write(''.join( format_traceback( extracted_tb, exception_type, exception_value, self._cwd, self._term, self._options.function_color, self._options.dim_color, self._options.editor)))
def _printTraceback(self, test, err): """Print a nicely formatted traceback. :arg err: exc_info()-style traceback triple :arg test: the test that precipitated this call """ # Don't bind third item to a local var; that can create # circular refs which are expensive to collect. See the # sys.exc_info() docs. exception_type, exception_value = err[:2] # TODO: In Python 3, the traceback is attached to the exception # instance through the __traceback__ attribute. If the instance # is saved in a local variable that persists outside the except # block, the traceback will create a reference cycle with the # current frame and its dictionary of local variables. This will # delay reclaiming dead resources until the next cyclic garbage # collection pass. extracted_tb = extract_relevant_tb( err[2], exception_type, exception_type is test.failureException) test_frame_index = index_of_test_frame( extracted_tb, exception_type, exception_value, test) if test_frame_index: # We have a good guess at which frame is the test, so # trim everything until that. We don't care to see test # framework frames. extracted_tb = extracted_tb[test_frame_index:] with self.bar.dodging(): self.stream.write(''.join( format_traceback( extracted_tb, exception_type, exception_value, self._cwd, self._term, self._options.function_color, self._options.dim_color, self._options.editor, self._options.editor_shortcut_template)))
def _printTraceback(self, test, err): """Print a nicely formatted traceback. :arg err: exc_info()-style traceback triple :arg test: the test that precipitated this call """ # Don't bind third item to a local var; that can create # circular refs which are expensive to collect. See the # sys.exc_info() docs. exception_type, exception_value = err[:2] extracted_tb = extract_relevant_tb( err[2], exception_type, exception_type is test.failureException) test_frame_index = index_of_test_frame( extracted_tb, exception_type, exception_value, test) if test_frame_index: # We have a good guess at which frame is the test, so # trim everything until that. We don't care to see test # framework frames. extracted_tb = extracted_tb[test_frame_index:] with self.bar.dodging(): self.stream.write(''.join( format_traceback( extracted_tb, exception_type, exception_value, self._cwd, self._term, self._options.function_color, self._options.dim_color, self._options.editor)))