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

hpk at codespeak.net hpk at codespeak.net
Sat Jan 24 22:35:10 CET 2009


Author: hpk
Date: Sat Jan 24 22:35:07 2009
New Revision: 61320

Modified:
   py/branch/pytestplugin/py/test/plugin/pytest_terminal.py
   py/branch/pytestplugin/py/test/plugin/pytest_xfail.py
   py/branch/pytestplugin/py/test/pmanage.py
   py/branch/pytestplugin/py/test/testing/plugintester.py
   py/branch/pytestplugin/py/test/testing/test_pmanage.py
Log:
start implementing neccessary support and hooks for xfail plugin, enable generic tests 


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	Sat Jan 24 22:35:07 2009
@@ -127,6 +127,12 @@
         self.ensure_newline()
         self._tw.sep(sep, title, **markup)
 
+    def getoutcomeletterword(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)
+
     def getoutcomeletter(self, event):
         return event.shortrepr 
 
@@ -183,12 +189,12 @@
     def rep_ItemTestReport(self, ev):
         super(TerminalReporter, self).rep_ItemTestReport(ev)
         fspath = ev.colitem.fspath 
+        letter, word = self.getoutcomeletterword(ev)
         if not self.config.option.verbose:
-            self.write_fspath_result(fspath, self.getoutcomeletter(ev))
+            self.write_fspath_result(fspath, letter)
         else:
             info = ev.colitem.repr_metainfo()
             line = info.verboseline(basedir=self.curdir) + " "
-            word = self.getoutcomeword(ev)
             self.write_ensure_prefix(line, word)
 
     def rep_CollectionReport(self, ev):

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	Sat Jan 24 22:35:07 2009
@@ -7,20 +7,20 @@
 """
 import py
 
-class Xfail:
-    def pytest_progress_resultevent(self, resultevent):
+class Xfail(object):
+    def pytest_report_teststatus(self, event):
         """ return category/verbose and shortletter. """
         if 'xfail' in resultevent.keywords: #the 
             if resultevent.failed:
-                return "xfailed", "x"
+                return "x", "xfailed"
             else:
-                return "passed_xfailed", "P"
+                return "P", "passed_xfailed"
 
     #def pytest_terminal_summary_category_sort(self, name1, name2):
     #    ... 
         
     # a hook implemented called by the terminalreporter instance/plugin
-    def pytest_terminal_summary_category(self, terminalreporter, categoryname, events):
+    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":
@@ -37,7 +37,6 @@
 from py.__.test.testing import plugintester
 
 def test_generic():
-    py.test.skip("implement various bits above first")
     impname = "py.__.test.plugin.pytest_xfail"
     plugintester.nocalls(impname) 
     tmpdir = plugintester.functional("py.__.test.plugin.pytest_xfail")

Modified: py/branch/pytestplugin/py/test/pmanage.py
==============================================================================
--- py/branch/pytestplugin/py/test/pmanage.py	(original)
+++ py/branch/pytestplugin/py/test/pmanage.py	Sat Jan 24 22:35:07 2009
@@ -9,6 +9,7 @@
 
 class PluginManager(object):
     def __init__(self):
+        # XXX turn this into ordered dict? 
         self._plugins = {}
 
     def addpluginclass(self, pluginclass):
@@ -56,10 +57,17 @@
         config.addoptions("ungrouped options added by plugins", *opts) 
 
     def callplugins(self, methname, **args):
-        """ call method with the given name for each plugin.  pass along kwargs. """
+        """ call all plugins with the given method name and args. """ 
         for name, method in self.listattr(methname):
             method(**args)
 
+    def callfirst(self, methname, **args):
+        """ call all plugins with the given method name and args. """ 
+        for name, method in self.listattr(methname):
+            res = method(**args)
+            if res is not None:
+                return res 
+
     def forward_event(self, event):
         self.callplugins("pytest_event", event=event)
 

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	Sat Jan 24 22:35:07 2009
@@ -12,6 +12,7 @@
     callhooklist = [
         ("pytest_configure", "config"), 
         ("pytest_unconfigure", "config"), 
+        ("pytest_report_teststatus", "event"),
         ("pytest_event", "event"), 
     ]
     plugin_pytest_methods = dict([item for item in vars(plugin.__class__).items() 
@@ -51,7 +52,7 @@
         setupfs(tmpdir)
         config.parse([tmpdir] + list(cmdlineopts)) 
         try:
-            config.pluginmanager.import_plugin(pname)
+            config.pluginmanager.import_plugin(impname)
         except ValueError:
             pass # already registered 
         plugin = config.pluginmanager.getplugin(pname)

Modified: py/branch/pytestplugin/py/test/testing/test_pmanage.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_pmanage.py	(original)
+++ py/branch/pytestplugin/py/test/testing/test_pmanage.py	Sat Jan 24 22:35:07 2009
@@ -80,6 +80,26 @@
         pm.callplugins("method", arg=42)
         py.test.raises(TypeError, 'pm.callplugins("method", arg=42, s=13)')
 
+    def test_callfirst(self):
+        pm = PluginManager()
+        class My1:
+            def method(self):
+                pass
+        class My2:
+            def method(self):
+                return True 
+        class My3:
+            def method(self):
+                return None
+        assert pm.callfirst("method") is None
+        assert pm.callfirst("methodnotexists") is None
+        pm.addpluginclass(My1)
+        assert pm.callfirst("method") is None
+        pm.addpluginclass(My2)
+        assert pm.callfirst("method") == True
+        pm.addpluginclass(My3)
+        assert pm.callfirst("method") == True
+
     def test_listattr(self):
         pm = PluginManager()
         class My2:



More information about the pytest-commit mailing list