[pypy-svn] r74384 - pypy/branch/py12/py/_plugin

hpk at codespeak.net hpk at codespeak.net
Wed May 5 20:20:23 CEST 2010


Author: hpk
Date: Wed May  5 20:20:21 2010
New Revision: 74384

Modified:
   pypy/branch/py12/py/_plugin/pytest_skipping.py
   pypy/branch/py12/py/_plugin/pytest_terminal.py
Log:
pull over newest py.test-1.3.0 release candidate changes


Modified: pypy/branch/py12/py/_plugin/pytest_skipping.py
==============================================================================
--- pypy/branch/py12/py/_plugin/pytest_skipping.py	(original)
+++ pypy/branch/py12/py/_plugin/pytest_skipping.py	Wed May  5 20:20:21 2010
@@ -10,9 +10,8 @@
 If a test fails under all conditions then it's probably better
 to mark your test as 'xfail'. 
 
-By passing ``--report=xfailed,skipped`` to the terminal reporter 
-you will see summary information on skips and xfail-run tests
-at the end of a test run. 
+By passing ``-rxs`` to the terminal reporter you will see extra
+summary information on skips and xfail-run tests at the end of a test run. 
 
 .. _skipif:
 
@@ -165,7 +164,7 @@
         expl = self.get('reason', None)
         if not expl:
             if not hasattr(self, 'expr'):
-                return "condition: True"
+                return ""
             else:
                 return "condition: " + self.expr
         return expl
@@ -222,31 +221,53 @@
 
 # called by the terminalreporter instance/plugin
 def pytest_terminal_summary(terminalreporter):
-    show_xfailed(terminalreporter)
-    show_skipped(terminalreporter)
-
-def show_xfailed(terminalreporter):
     tr = terminalreporter
-    xfailed = tr.stats.get("xfailed")
+    if not tr.reportchars:
+        #for name in "xfailed skipped failed xpassed":
+        #    if not tr.stats.get(name, 0):
+        #        tr.write_line("HINT: use '-r' option to see extra "
+        #              "summary info about tests")
+        #        break
+        return
+
+    lines = []
+    for char in tr.reportchars:
+        if char == "x":
+            show_xfailed(terminalreporter, lines)
+        elif char == "X":
+            show_xpassed(terminalreporter, lines)
+        elif char == "f":
+            show_failed(terminalreporter, lines)
+        elif char == "s":
+            show_skipped(terminalreporter, lines)
+    if lines:
+        tr._tw.sep("=", "short test summary info")
+        for line in lines:
+            tr._tw.line(line)
+
+def show_failed(terminalreporter, lines):
+    tw = terminalreporter._tw
+    failed = terminalreporter.stats.get("failed")
+    if failed:
+        for rep in failed:
+            pos = terminalreporter.gettestid(rep.item)
+            lines.append("FAIL %s" %(pos, ))
+
+def show_xfailed(terminalreporter, lines):
+    xfailed = terminalreporter.stats.get("xfailed")
     if xfailed:
-        if not tr.hasopt('xfailed'):
-            tr.write_line(
-              "%d expected failures, use --report=xfailed for more info" %
-              len(xfailed))
-            return
-        tr.write_sep("_", "expected failures")
         for rep in xfailed:
             pos = terminalreporter.gettestid(rep.item)
             reason = rep.keywords['xfail']
-            tr._tw.line("%s %s" %(pos, reason))
+            lines.append("XFAIL %s %s" %(pos, reason))
 
+def show_xpassed(terminalreporter, lines):
     xpassed = terminalreporter.stats.get("xpassed")
     if xpassed:
-        tr.write_sep("_", "UNEXPECTEDLY PASSING TESTS")
         for rep in xpassed:
             pos = terminalreporter.gettestid(rep.item)
             reason = rep.keywords['xfail']
-            tr._tw.line("%s %s" %(pos, reason))
+            lines.append("XPASS %s %s" %(pos, reason))
 
 def cached_eval(config, expr, d):
     if not hasattr(config, '_evalcache'):
@@ -271,17 +292,20 @@
         l.append((len(events),) + key)
     return l 
 
-def show_skipped(terminalreporter):
+def show_skipped(terminalreporter, lines):
     tr = terminalreporter
     skipped = tr.stats.get('skipped', [])
     if skipped:
-        if not tr.hasopt('skipped'):
-            tr.write_line(
-                "%d skipped tests, use --report=skipped for more info" %
-                len(skipped))
-            return
+        #if not tr.hasopt('skipped'):
+        #    tr.write_line(
+        #        "%d skipped tests, specify -rs for more info" %
+        #        len(skipped))
+        #    return
         fskips = folded_skips(skipped)
         if fskips:
-            tr.write_sep("_", "skipped test summary")
+            #tr.write_sep("_", "skipped test summary")
             for num, fspath, lineno, reason in fskips:
-                tr._tw.line("%s:%d: [%d] %s" %(fspath, lineno, num, reason))
+                if reason.startswith("Skipped: "):
+                    reason = reason[9:]
+                lines.append("SKIP [%d] %s:%d: %s" %
+                    (num, fspath, lineno, reason))

Modified: pypy/branch/py12/py/_plugin/pytest_terminal.py
==============================================================================
--- pypy/branch/py12/py/_plugin/pytest_terminal.py	(original)
+++ pypy/branch/py12/py/_plugin/pytest_terminal.py	Wed May  5 20:20:21 2010
@@ -12,12 +12,16 @@
     group = parser.getgroup("terminal reporting", "reporting", after="general")
     group._addoption('-v', '--verbose', action="count", 
                dest="verbose", default=0, help="increase verbosity."),
+    group._addoption('-r',
+         action="store", dest="reportchars", default=None, metavar="chars",
+         help="show extra test summary info as specified by chars (f)ailed, "
+              "(s)skipped, (x)failed, (X)passed.")
     group._addoption('-l', '--showlocals',
-               action="store_true", dest="showlocals", default=False,
-               help="show locals in tracebacks (disabled by default).")
-    group.addoption('--report',
-               action="store", dest="report", default=None, metavar="opts",
-               help="show more info, valid: skipped,xfailed")
+         action="store_true", dest="showlocals", default=False,
+         help="show locals in tracebacks (disabled by default).")
+    group._addoption('--report',
+         action="store", dest="report", default=None, metavar="opts",
+         help="(deprecated, use -r)")
     group._addoption('--tb', metavar="style", 
                action="store", dest="tbstyle", default='long',
                type="choice", choices=['long', 'short', 'no', 'line'],
@@ -47,17 +51,25 @@
                 setattr(reporter._tw, name, getattr(config, attr))
         config.pluginmanager.register(reporter, 'terminalreporter')
 
-def getreportopt(optvalue):
-    d = {}
+def getreportopt(config):
+    reportopts = ""
+    optvalue = config.getvalue("report")
     if optvalue:
-        for setting in optvalue.split(","):
-            setting = setting.strip()
-            val = True
-            if setting.startswith("no"):
-                val = False
-                setting = setting[2:]
-            d[setting] = val
-    return d
+        py.builtin.print_("DEPRECATED: use -r instead of --report option.", 
+            file=py.std.sys.stderr)
+        if optvalue:
+            for setting in optvalue.split(","):
+                setting = setting.strip()
+                if setting == "skipped":
+                    reportopts += "s"
+                elif setting == "xfailed":
+                    reportopts += "x"
+    reportchars = config.getvalue("reportchars")
+    if reportchars:
+        for char in reportchars:
+            if char not in reportopts:
+                reportopts += char
+    return reportopts
 
 class TerminalReporter:
     def __init__(self, config, file=None):
@@ -69,10 +81,11 @@
         self._tw = py.io.TerminalWriter(file)
         self.currentfspath = None 
         self.gateway2info = {}
-        self._reportopt = getreportopt(config.getvalue('report'))
+        self.reportchars = getreportopt(config)
 
-    def hasopt(self, name):
-        return self._reportopt.get(name, False)
+    def hasopt(self, char):
+        char = {'xfailed': 'x', 'skipped': 's'}.get(char,char)
+        return char in self.reportchars
 
     def write_fspath_result(self, fspath, res):
         fspath = self.curdir.bestrelpath(fspath)



More information about the Pypy-commit mailing list