def test_pick_tb_lines(self): try: val = "fred" def defred(n): return n.replace('fred', '') assert defred(val) == 'barney', "Fred - fred != barney?" except AssertionError: et, ev, tb = sys.exc_info() out = inspect_traceback(tb) # print "'%s'" % out.strip() self.assertEqual(out.strip(), ">> assert defred('fred') == 'barney', " '"Fred - fred != barney?"') try: val = "fred" def defred(n): return n.replace('fred', '') assert defred(val) == 'barney', \ "Fred - fred != barney?" def refred(n): return n + 'fred' except AssertionError: et, ev, tb = sys.exc_info() out = inspect_traceback(tb) # print "'%s'" % out.strip() self.assertEqual(out.strip(), ">> assert defred('fred') == 'barney', " '\\\n "Fred - fred != barney?"') S = {'setup': 1} def check_even(n, nn): assert S['setup'] print n, nn assert n % 2 == 0 or nn % 2 == 0 try: check_even(1, 3) except AssertionError: et, ev, tb = sys.exc_info() out = inspect_traceback(tb) print "'%s'" % out.strip() if sys.version_info < (3,): print_line = " print 1, 3\n" else: print_line = " print(1, 3)\n" self.assertEqual(out.strip(), "assert {'setup': 1}['setup']\n" + print_line + ">> assert 1 % 2 == 0 or 3 % 2 == 0")
def test_pick_tb_lines(self): try: val = "fred" def defred(n): return n.replace('fred','') assert defred(val) == 'barney', "Fred - fred != barney?" except AssertionError: et, ev, tb = sys.exc_info() out = inspect_traceback(tb) # print "'%s'" % out.strip() self.assertEqual(out.strip(), ">> assert defred('fred') == 'barney', " '"Fred - fred != barney?"') try: val = "fred" def defred(n): return n.replace('fred','') assert defred(val) == 'barney', \ "Fred - fred != barney?" def refred(n): return n + 'fred' except AssertionError: et, ev, tb = sys.exc_info() out = inspect_traceback(tb) #print "'%s'" % out.strip() self.assertEqual(out.strip(), ">> assert defred('fred') == 'barney', " '\\\n "Fred - fred != barney?"') S = {'setup':1} def check_even(n, nn): assert S['setup'] print n, nn assert n % 2 == 0 or nn % 2 == 0 try: check_even(1, 3) except AssertionError: et, ev, tb = sys.exc_info() out = inspect_traceback(tb) print "'%s'" % out.strip() if sys.version_info < (3,): print_line = " print 1, 3\n" else: print_line = " print(1, 3)\n" self.assertEqual(out.strip(), "assert {'setup': 1}['setup']\n" + print_line + ">> assert 1 % 2 == 0 or 3 % 2 == 0")
def formatFailure(self, test, err): """Add detail from traceback inspection to error message of a failure. """ ec, ev, tb = err tbinfo = inspect_traceback(tb) test.tbinfo = tbinfo return (ec, '\n'.join([str(ev), tbinfo]), tb)
def string_for_traceback(self, exc_info): tb = "".join(traceback.format_exception(*exc_info)) # nose's inspect_traceback blows up when run on exceptions thrown out # of Cython. FIXME: file nose bug try: details = inspect_traceback(exc_info[2]) except SystemExit, KeyboardInterrupt: raise
def string_for_traceback(self, exc_info): tb = "".join(traceback.format_exception(*exc_info)) # nose's inspect_traceback blows up when run on exceptions thrown out # of Pyrex. FIXME: file nose bug try: details = inspect_traceback(exc_info[2]) except SystemExit, KeyboardInterrupt: raise
def write_report(self, test, status, err=None): from nose.inspector import inspect_traceback truncate_output_mark = '-------------------- >> begin captured stdout' truncate_output_len = len(truncate_output_mark) # record the end time here, because nose does not always call stopTest() self.pdk_endtime = time.time() # Tracebacks / Exceptions tbinfo = None exc = None exc_tra = None # Collect stdout (returns None on failure to acquire stream) capture = get_stdout() # Handle exception information if err is not None: ec, ev, tb = err str_ec = ec.__name__.lstrip() str_ev = str(ev) # Alert on no error message if not str_ev: str_ev = '(No message)' # Extract traceback message if tb: tbinfo = inspect_traceback(tb) str_rv = '\n'.join([tbinfo]) str_tb = ''.join(traceback.format_tb(tb)) # Remove redundant stdout messages str_ev_mark = str_ev.find(truncate_output_mark) if str_ev_mark >= 0: str_ev_truncated = str_ev[0:str_ev_mark] else: str_ev_truncated = str_ev # Compile exception message exc_tra = '{}: {}'.format(str_ec, str_ev_truncated) exc = 'Type: {}\nMessage: {}\nTrigger: {}\n'.format( str_ec, str_ev_truncated, str_tb.splitlines()[-1].lstrip()) final_tb = str_tb + '\n' + 'EXCEPTION\n' + exc if capture is None: capture = final_tb else: capture += final_tb # Suppress tra_exception if marked as failure if status == 'F': exc_tra = None # Write the record to the log file self.pdklog(test.test, status, log=capture, exc=exc_tra)
def write_report(self, test, status, err=None): from nose.inspector import inspect_traceback truncate_output_mark = '-------------------- >> begin captured stdout' truncate_output_len = len(truncate_output_mark) # record the end time here, because nose does not always call stopTest() self.pdk_endtime = time.time() # Tracebacks / Exceptions tbinfo = None exc = None exc_tra = None # Collect stdout (returns None on failure to acquire stream) capture = get_stdout() # Handle exception information if err is not None: ec, ev, tb = err str_ec = ec.__name__.lstrip() str_ev = str(ev) # Alert on no error message if not str_ev: str_ev = '(No message)' # Extract traceback message if tb: tbinfo = inspect_traceback(tb) str_rv = '\n'.join([tbinfo]) str_tb = ''.join(traceback.format_tb(tb)) # Remove redundant stdout messages str_ev_mark = str_ev.find(truncate_output_mark) if str_ev_mark >= 0: str_ev_truncated = str_ev[0:str_ev_mark] else: str_ev_truncated = str_ev # Compile exception message exc_tra = '{}: {}'.format(str_ec, str_ev_truncated) exc = 'Type: {}\nMessage: {}\nTrigger: {}\n'.format(str_ec, str_ev_truncated, str_tb.splitlines()[-1].lstrip()) final_tb = str_tb + '\n' + 'EXCEPTION\n' + exc if capture is None: capture = final_tb else: capture += final_tb # Suppress tra_exception if marked as failure if status == 'F': exc_tra = None # Write the record to the log file self.pdklog(test.test, status, log=capture, exc=exc_tra)
def formatError(self, test, err): """Add detail from traceback inspection and MMM logs to error message """ ec, ev, tb = err tbinfo = inspect_traceback(tb) test.tbinfo = tbinfo mmm_log = self._get_per_test_logs(test) return (ec, '\n'.join([str(ev), tbinfo, mmm_log]), tb)
def formatFailure(self, test, err): """Add detail from traceback inspection to error message of a failure. """ ec, ev, tb = err tbinfo, str_ev = None, exc_to_unicode(ev) if tb: tbinfo = force_unicode(inspect_traceback(tb)) str_ev = '\n'.join([str_ev, tbinfo]) test.tbinfo = tbinfo return (ec, str_ev, tb)
def test_inspect_traceback_continued(self): a = 6 out = '' try: assert a < 1, \ "This is a multline expression" except AssertionError: et, ev, tb = sys.exc_info() out = inspect_traceback(tb) # print "'%s'" % out.strip() self.assertEqual( out.strip(), '>> assert 6 < 1, \\\n ' '"This is a multline expression"')
def test_inspect_traceback_continued(self): a = 6 out = '' try: assert a < 1, \ "This is a multline expression" except AssertionError: et, ev, tb = sys.exc_info() out = inspect_traceback(tb) # print "'%s'" % out.strip() self.assertEqual(out.strip(), '>> assert 6 < 1, \\\n ' '"This is a multline expression"')
def test_bug_95(self): """Test that inspector can handle multi-line docstrings""" try: """docstring line 1 docstring line 2 """ a = 2 assert a == 4 except AssertionError: et, ev, tb = sys.exc_info() out = inspect_traceback(tb) print "'%s'" % out.strip() self.assertEqual(out.strip(), "2 = 2\n" ">> assert 2 == 4")
def string_for_traceback(self, exc_info): tb = "".join(traceback.format_exception(*exc_info)) # nose's inspect_traceback blows up when run on exceptions thrown out # of Cython. FIXME: file nose bug try: details = inspect_traceback(exc_info[2]) except SystemExit: raise except KeyboardInterrupt: raise except Exception: details = ("(failed to extract details;\n" + "nose.inspect.inspect_traceback threw exception\n" + "(maybe because the error was in cython code):\n" + traceback.format_exc() + ")") return "%s\nDetails of failing source code:\n%s" % (tb, details)
def write_report(self, test, status, err=None): from nose.inspector import inspect_traceback # record the end time here, because nose does not always call stopTest() self.pdk_endtime = time.time() # Limits exc_maxlen = 255 # Tracebacks / Exceptions tbinfo = None exc = None # Collect stdout (returns None on failure to acquire stream) capture = get_stdout() # Handle exception information if err is not None: ec, ev, tb = err str_ec = ec.__name__.lstrip() str_ev = str(ev).lstrip() str_ev_len = len(str_ev) # Alert on no error message if not str_ev: str_ev = '(No message)' # Extract traceback message if tb: tbinfo = inspect_traceback(tb) str_rv = '\n'.join([tbinfo]) str_tb = ''.join(traceback.format_tb(tb)) # Compile exception message exc = 'Type: {}\nMessage: {}\nTrigger: {}\n'.format( str_ec, str_ev, str_tb.splitlines()[-1].lstrip()) final_tb = str_tb + '\n' + 'EXCEPTION\n' + exc if capture is None: capture = final_tb else: capture += final_tb # Write the record to the log file self.pdklog(test.test, status, log=capture, exc=exc)
def addFailure(self, test, err): self.capt = self.getBuffer() if self.conf.debugFailures: if self.conf.capture: end_capture() pdb.post_mortem(err[2]) if self.conf.capture: start_capture() if self.conf.detailedErrors: try: self.tbinfo = inspect_traceback(err[2]) except tokenize.TokenError: self.tbinfo = "ERR: unable to inspect traceback" else: self.tbinfo = '' self.resetBuffer() call_plugins(self.conf.plugins, 'addFailure', test, err, self.capt, self.tbinfo) if self.conf.stopOnError: self.shouldStop = True