Example #1
0
 def test_frame_of_test_null_file(self):
     """Make sure frame_of_test() doesn't crash when test_file is None."""
     try:
         frame_of_test((None, None, None), NotImplementedError,
                       NotImplementedError(), [('file', 333)])
     except AttributeError:
         self.fail('frame_of_test() raised AttributeError.')
Example #2
0
    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._showAdvisories:
            # 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_tb(err[2])
            formatted_traceback = ''.join(format_list(extracted_tb))
            # TODO: Canonicalize the path to remove /kitsune/../kitsune
            # nonsense. Don't relativize, though, as that hurts the ability to
            # paste into running editors.
            writeln = self.stream.writeln
            write = self.stream.write
            with self.bar.dodging():
                writeln('\n' + (self._codes['bold'] if isFailure else '') +
                        '%s: %s' % (kind, nose_selector(test)))

                if isFailure:  # Then show traceback
                    # File name and line num in a format vi can take:
                    try:
                        address = test_address(test)
                    except TypeError:
                        # Explodes if the function passed to @with_setup
                        # applied to a test generator has an error.
                        address = None
                    if address:  # None if no such callable found. No sense
                                 # trying to find the test frame if there's no
                                 # such thing.
                        file, line = frame_of_test(address,
                                                   exception_type,
                                                   exception_value,
                                                   extracted_tb)[:2]
                        writeln(' ' * len(kind) + '  %s +%s %s' %
                                (os.environ.get('EDITOR', 'vi'), line,
                                 human_path(src(file), self._cwd)))

                    write(self._codes['sgr0'])  # end bold

                    # Traceback:
                    # TODO: Think about using self._exc_info_to_string, which
                    # does some pretty whizzy skipping of unittest frames.
                    write(formatted_traceback)

                    # Exception:
                    write(''.join(format_exception_only(exception_type,
                                                        exception_value)))
                else:
                    write(self._codes['sgr0'])  # end bold