[py-svn] r20815 - in py/dist/py/test: . terminal

arigo at codespeak.net arigo at codespeak.net
Tue Dec 6 21:45:29 CET 2005


Author: arigo
Date: Tue Dec  6 21:45:27 2005
New Revision: 20815

Modified:
   py/dist/py/test/defaultconftest.py
   py/dist/py/test/terminal/terminal.py
Log:
Added the --tb=long/short/no option.  This is a bit messy to implement...

The default is 'long', which works as previously; 'short' prints shorter
Python-style tracebacks; 'no' suppresses all output at the end of the run
except the single summary line (this mode is useful when performing large
refactorings, as experienced in PyPy's somepbc-refactoring branch).



Modified: py/dist/py/test/defaultconftest.py
==============================================================================
--- py/dist/py/test/defaultconftest.py	(original)
+++ py/dist/py/test/defaultconftest.py	Tue Dec  6 21:45:27 2005
@@ -30,6 +30,10 @@
         Option('', '--pdb',
                action="store_true", dest="usepdb", default=False,
                help="start pdb (the Python debugger) on errors."),
+        Option('', '--tb',
+               action="store", dest="tbstyle", default='long',
+               type="choice", choices=['long', 'short', 'no'],
+               help="traceback verboseness (long/short/no)"),
         Option('', '--fulltrace',
                action="store_true", dest="fulltrace", default=False,
                help="don't cut any tracebacks (default is to cut)"),

Modified: py/dist/py/test/terminal/terminal.py
==============================================================================
--- py/dist/py/test/terminal/terminal.py	(original)
+++ py/dist/py/test/terminal/terminal.py	Tue Dec  6 21:45:27 2005
@@ -243,6 +243,8 @@
                 self.out.line()
 
     def failures(self):
+        if self.config.option.tbstyle == 'no':
+            return   # skip the detailed failure reports altogether
         l = self.getitemoutcomepairs(Item.Failed)
         if l: 
             self.out.sep('_')
@@ -264,12 +266,16 @@
         if not traceback: 
             self.out.line("empty traceback from item %r" % (item,)) 
             return
-        last = traceback[-1]
-        first = traceback[0]
+        handler = getattr(self, 'repr_failure_tb%s' % self.config.option.tbstyle)
+        handler(item, excinfo, traceback)
+
+    def repr_failure_tblong(self, item, excinfo, traceback):
         if not self.config.option.nomagic and excinfo.errisinstance(RuntimeError):
             recursionindex = traceback.recursionindex()
         else:
             recursionindex = None
+        last = traceback[-1]
+        first = traceback[0]
         for index, entry in py.builtin.enumerate(traceback): 
             if entry == first: 
                 if item: 
@@ -300,6 +306,45 @@
                     self.out.sep("!")
                     break 
 
+    def repr_failure_tbshort(self, item, excinfo, traceback):
+        # print a Python-style short traceback
+        if not self.config.option.nomagic and excinfo.errisinstance(RuntimeError):
+            recursionindex = traceback.recursionindex()
+        else:
+            recursionindex = None
+        last = traceback[-1]
+        first = traceback[0]
+        self.out.line()
+        for index, entry in py.builtin.enumerate(traceback): 
+            code = entry.frame.code
+            self.out.line('  File "%s", line %d, in %s' % (
+                code.raw.co_filename, entry.lineno+1, code.raw.co_name))
+            fullsource = entry.frame.code.fullsource
+            try:
+                source = [fullsource[entry.lineno].lstrip()]
+            except IndexError:
+                source = []
+            if entry == last:
+                if source:
+                    self.repr_source(source, 'E')
+                self.repr_failure_explanation(excinfo, source) 
+            else:
+                if source:
+                    self.repr_source(source, ' ')
+            self.repr_locals(entry) 
+
+            # trailing info 
+            if entry == last: 
+                #if item: 
+                #    self.repr_failure_info(item, entry) 
+                self.repr_out_err(item) 
+                self.out.sep("_")
+            else: 
+                if index == recursionindex:
+                    self.out.line("Recursion detected (same locals & position)")
+                    self.out.sep("!")
+                    break 
+
     def repr_failure_info(self, item, entry): 
         root = item.fspath 
         modpath = item.getmodpath() 



More information about the pytest-commit mailing list