[py-svn] r61368 - in py/branch/pytestplugin/py/test: plugin testing

hpk at codespeak.net hpk at codespeak.net
Mon Jan 26 18:07:30 CET 2009


Author: hpk
Date: Mon Jan 26 18:07:29 2009
New Revision: 61368

Modified:
   py/branch/pytestplugin/py/test/plugin/pytest_terminal.py
   py/branch/pytestplugin/py/test/plugin/pytest_xfail.py
   py/branch/pytestplugin/py/test/testing/plugintester.py
Log:
xfail plugin begins to work and pass an acceptance test. 



Modified: py/branch/pytestplugin/py/test/plugin/pytest_terminal.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/pytest_terminal.py	(original)
+++ py/branch/pytestplugin/py/test/plugin/pytest_terminal.py	Mon Jan 26 18:07:29 2009
@@ -120,11 +120,14 @@
         self.ensure_newline()
         self._tw.sep(sep, title, **markup)
 
-    def getoutcomeletterword(self, event):
+    def getcategoryletterword(self, event):
         result = self.config.pluginmanager.callfirst("pytest_report_teststatus", event=event)
         if result is not None:
             return result 
-        return self.getoutcomeletter(event), self.getoutcomeword(event)
+        for cat in 'skipped failed passed ???'.split():
+            if getattr(event, cat, None):
+                break 
+        return cat, self.getoutcomeletter(event), self.getoutcomeword(event)
 
     def getoutcomeletter(self, event):
         return event.shortrepr 
@@ -180,9 +183,10 @@
             self.write_sep("!", "RESCHEDULING %s " %(ev.items,))
     
     def rep_ItemTestReport(self, ev):
-        super(TerminalReporter, self).rep_ItemTestReport(ev)
+        #super(TerminalReporter, self).rep_ItemTestReport(ev)
         fspath = ev.colitem.fspath 
-        letter, word = self.getoutcomeletterword(ev)
+        cat, letter, word = self.getcategoryletterword(ev)
+        self.status2event.setdefault(cat, []).append(ev)
         if not self.config.option.verbose:
             self.write_fspath_result(fspath, letter)
         else:
@@ -210,6 +214,7 @@
         if ev.exitstatus in (0, 1, 2):
             self.summary_failures()
             self.summary_skips()
+            self.config.pluginmanager.callplugins("pytest_terminal_summary", terminalreporter=self)
         if ev.excrepr is not None:
             self.summary_final_exc(ev.excrepr)
         if ev.exitstatus == 2:

Modified: py/branch/pytestplugin/py/test/plugin/pytest_xfail.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/pytest_xfail.py	(original)
+++ py/branch/pytestplugin/py/test/plugin/pytest_xfail.py	Mon Jan 26 18:07:29 2009
@@ -8,25 +8,32 @@
 import py
 
 class Xfail(object):
+
     def pytest_report_teststatus(self, event):
         """ return shortletter and verbose word. """
-        if 'xfail' in resultevent.keywords: 
-            if resultevent.failed:
-                return "passed", "x", "xfail"
+        if 'xfail' in event.keywords: 
+            if event.failed:
+                return "xfailed", "x", "xfail"
             else:
-                return "failed", "P", "xpass" 
+                return "xpassed", "P", "xpass" 
 
-    #def pytest_terminal_summary_category_sort(self, name1, name2):
-    #    ... 
-        
     # a hook implemented called by the terminalreporter instance/plugin
-    def xxx_pytest_terminal_summary_category(self, terminalreporter, categoryname, events):
-        if categoryname == "xfailed":
-            return True  # print nothing for tests that failed and were expected to fail 
-        elif category.name == "passed_xfailed":
-            self.write_sep("=", "unexpectedly passing tests")
-            for ev in events: 
-                ev.toterminal(self._tw)  # XXX somehow list all passing tests 
+    def pytest_terminal_summary(self, terminalreporter):
+        tr = terminalreporter
+        xfailed = tr.status2event.get("xfailed")
+        if xfailed:
+            tr.write_sep("_", "EXPECTED XFAILURES")
+            for event in xfailed:
+                entry = event.longrepr.reprcrash 
+                key = entry.path, entry.lineno, entry.message
+                reason = event.longrepr.reprcrash.message
+                tr._tw.line("%s:%d: %s" %(entry.path, entry.lineno, entry.message))
+
+        xpassed = terminalreporter.status2event.get("xpassed")
+        if xpassed:
+            tr.write_sep("_", "UNEXPECTEDLY PASSING")
+            for event in xpassed:
+                tr._tw.line("%s: xpassed" %(event.colitem,))
 
 # ===============================================================================
 #
@@ -39,5 +46,21 @@
 def test_generic():
     impname = "py.__.test.plugin.pytest_xfail"
     plugintester.nocalls(impname) 
-    tmpdir = plugintester.functional("py.__.test.plugin.pytest_xfail")
-    # XXX
+               
+from py.__.test.testing.acceptance_test import AcceptBase, assert_lines_contain_lines
+ 
+class TestXFailAcceptance(AcceptBase):
+    def test_xfail(self):
+        p = self.makepyfile(test_one="""
+            import py
+            @py.test.keywords(xfail=True)
+            def test_this():
+                assert 0
+        """)
+        self.makepyfile(conftest="""pytest_plugins_required='py.__.test.plugin.pytest_xfail',""")
+        result = self.runpytest(p)
+        extra = assert_lines_contain_lines(result.outlines, [
+            "*XFAILURES*",
+            "*test_one.py:4: assert 0*",
+        ])
+        assert result.ret == 1

Modified: py/branch/pytestplugin/py/test/testing/plugintester.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/plugintester.py	(original)
+++ py/branch/pytestplugin/py/test/testing/plugintester.py	Mon Jan 26 18:07:29 2009
@@ -13,6 +13,7 @@
         ("pytest_configure", "config"), 
         ("pytest_unconfigure", "config"), 
         ("pytest_report_teststatus", "event"),
+        ("pytest_terminal_summary", "terminalreporter"),
         ("pytest_event", "event"), 
     ]
     plugin_pytest_methods = dict([item for item in vars(plugin.__class__).items() 



More information about the pytest-commit mailing list