[py-svn] r61750 - py/branch/pytestplugin/py/test/plugin

hpk at codespeak.net hpk at codespeak.net
Wed Feb 11 19:09:20 CET 2009


Author: hpk
Date: Wed Feb 11 19:09:20 2009
New Revision: 61750

Added:
   py/branch/pytestplugin/py/test/plugin/pytest_pocoo.py   (contents, props changed)
Log:
add new plugin for sending failures to paste.pocoo.org


Added: py/branch/pytestplugin/py/test/plugin/pytest_pocoo.py
==============================================================================
--- (empty file)
+++ py/branch/pytestplugin/py/test/plugin/pytest_pocoo.py	Wed Feb 11 19:09:20 2009
@@ -0,0 +1,64 @@
+"""
+py.test plugin for sending testing failure information to paste.pocoo.org 
+"""
+import py
+
+class url:
+    base = "http://paste.pocoo.org"
+    xmlrpc = base + "/xmlrpc/"
+    show = base + "/show/"
+
+class Pocoo(object):
+    pytest_cmdlineoptions = [ 
+        py.test.config.Option('--pocoo-sendfailures', 
+            action='store_true', dest="pocoo_sendfailures", 
+            help="send failures to %s" %(url.base,))
+    ]
+
+    def getproxy(self):
+        return py.std.xmlrpclib.ServerProxy(url.xmlrpc).pastes
+
+    def pytest_terminal_summary(self, terminalreporter):
+        if terminalreporter.config.option.pocoo_sendfailures:
+            tr = terminalreporter
+            if "failed" in tr.status2event and tr.config.option.tbstyle != "no":
+                terminalreporter.write_sep("=", "Sending failures to %s" %(url.base,))
+                terminalreporter.write_line("xmlrpcurl: %s" %(url.xmlrpc,))
+                serverproxy = self.getproxy()
+                for ev in terminalreporter.status2event['failed']:
+                    tw = py.io.TerminalWriter(stringio=True)
+                    ev.toterminal(tw)
+                    s = tw.stringio.getvalue()
+                    # XXX add failure summary 
+                    assert len(s)
+                    terminalreporter.write_line("newpaste() ...")
+                    id = serverproxy.newPaste("python", s)
+                    terminalreporter.write_line("%s%s\n" % (url.show, id))
+                    break
+
+def test_apicheck(plugintester):
+    plugintester.apicheck()
+
+def test_toproxy(fstester):
+    fstester.makepyfile(conftest="pytest_plugins='pytest_pocoo',")
+    testpath = fstester.makepyfile("""
+        import py
+        def test_pass():
+            pass
+        def test_fail():
+            assert 0
+        def test_skip():
+            py.test.skip("")
+    """)
+    l = []
+    class MockProxy:
+        def newPaste(self, language, code):
+            l.append((language, code))
+            
+    old = Pocoo.getproxy 
+    Pocoo.getproxy = MockProxy
+    try:
+        result = fstester.parse_and_run(testpath, "--pocoo-sendfailures")
+    finally:
+        Pocoo.getproxy = old
+    assert len(l) == 1



More information about the pytest-commit mailing list