[py-svn] r62610 - in py/trunk/py/test: dsession/testing plugin

hpk at codespeak.net hpk at codespeak.net
Thu Mar 5 22:01:10 CET 2009


Author: hpk
Date: Thu Mar  5 22:01:08 2009
New Revision: 62610

Modified:
   py/trunk/py/test/dsession/testing/test_functional_dsession.py
   py/trunk/py/test/plugin/pytest_doctest.py
   py/trunk/py/test/plugin/pytest_pocoo.py
   py/trunk/py/test/plugin/pytest_pytester.py
Log:
finally fixed a bug related to the global SetupState
for test functions.  streamlined  testdir.inline_run 
functions.  well killed most of them. 




Modified: py/trunk/py/test/dsession/testing/test_functional_dsession.py
==============================================================================
--- py/trunk/py/test/dsession/testing/test_functional_dsession.py	(original)
+++ py/trunk/py/test/dsession/testing/test_functional_dsession.py	Thu Mar  5 22:01:08 2009
@@ -90,11 +90,8 @@
             #    assert py.__file__ != '%s'
         """ % (tmpdir.join(subdir), py.__file__)))
         destdir.join("py").mksymlinkto(py.path.local(py.__file__).dirpath())
-        config = py.test.config._reparse([tmpdir.join(subdir)])
-        assert config.topdir == tmpdir
-        assert not tmpdir.join("__init__.py").check()
-        dist = DSession(config)
-        sorter = testdir.inline_runsession(dist)
+
+        sorter = testdir.inline_run(tmpdir.join(subdir))
         testevents = sorter.getnamed('itemtestreport')
         assert len([x for x in testevents if x.passed]) == 2
         assert len([x for x in testevents if x.failed]) == 3

Modified: py/trunk/py/test/plugin/pytest_doctest.py
==============================================================================
--- py/trunk/py/test/plugin/pytest_doctest.py	(original)
+++ py/trunk/py/test/plugin/pytest_doctest.py	Thu Mar  5 22:01:08 2009
@@ -107,7 +107,7 @@
             >>> x == 1
             False
         """)
-        events = testdir.inline_run_with_plugins(p)
+        events = testdir.inline_run(p)
         ev, = events.getnamed("itemtestreport")
         assert ev.failed 
 
@@ -143,7 +143,7 @@
 
             '''
         """)
-        events = testdir.inline_run_with_plugins(p, "--doctest-modules")
+        events = testdir.inline_run(p, "--doctest-modules")
         ev, = events.getnamed("itemtestreport")
         assert ev.failed 
 

Modified: py/trunk/py/test/plugin/pytest_pocoo.py
==============================================================================
--- py/trunk/py/test/plugin/pytest_pocoo.py	(original)
+++ py/trunk/py/test/plugin/pytest_pocoo.py	Thu Mar  5 22:01:08 2009
@@ -8,15 +8,16 @@
     xmlrpc = base + "/xmlrpc/"
     show = base + "/show/"
 
-class PocooPlugin(object):
+class PocooPlugin:
     """ report URLs from sending test failures to the pocoo paste service. """
 
     def pytest_addoption(self, parser):
-        parser.addoption('--pocoo-sendfailures', 
+        parser.addoption('-P', '--pocoo-sendfailures', 
             action='store_true', dest="pocoo_sendfailures", 
             help="send failures to %s" %(url.base,))
 
     def getproxy(self):
+        assert 0
         return py.std.xmlrpclib.ServerProxy(url.xmlrpc).pastes
 
     def pytest_terminal_summary(self, terminalreporter):
@@ -25,6 +26,8 @@
             if 'failed' in tr.stats and tr.config.option.tbstyle != "no":
                 terminalreporter.write_sep("=", "Sending failures to %s" %(url.base,))
                 terminalreporter.write_line("xmlrpcurl: %s" %(url.xmlrpc,))
+                print self.__class__.getproxy
+                print self.__class__, id(self.__class__)
                 serverproxy = self.getproxy()
                 for ev in terminalreporter.stats.get('failed'):
                     tw = py.io.TerminalWriter(stringio=True)
@@ -33,17 +36,22 @@
                     # 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))
+                    proxyid = serverproxy.newPaste("python", s)
+                    terminalreporter.write_line("%s%s\n" % (url.show, proxyid))
                     break
 
 
 def test_apicheck(plugintester):
     plugintester.apicheck(PocooPlugin)
 
-pytest_plugins = 'pytest_monkeypatch', 
 def test_toproxy(testdir, monkeypatch):
-    testdir.makepyfile(conftest="pytest_plugins='pytest_pocoo',")
+    l = []
+    class MockProxy:
+        def newPaste(self, language, code):
+            l.append((language, code))
+    monkeypatch.setattr(PocooPlugin, 'getproxy', MockProxy) 
+    testdir.plugins.insert(0, PocooPlugin())
+    testdir.chdir()
     testpath = testdir.makepyfile("""
         import py
         def test_pass():
@@ -53,10 +61,10 @@
         def test_skip():
             py.test.skip("")
     """)
-    l = []
-    class MockProxy:
-        def newPaste(self, language, code):
-            l.append((language, code))
-          
-    monkeypatch.setattr(PocooPlugin, 'getproxy', MockProxy) 
-    result = testdir.inline_run(testpath, "--pocoo-sendfailures")
+    evrec = testdir.inline_run(testpath, "-P")
+    assert len(l) == 1
+    assert l[0][0] == "python"
+    s = l[0][1]
+    assert s.find("def test_fail") != -1
+    assert evrec.countoutcomes() == [1,1,1]
+     

Modified: py/trunk/py/test/plugin/pytest_pytester.py
==============================================================================
--- py/trunk/py/test/plugin/pytest_pytester.py	(original)
+++ py/trunk/py/test/plugin/pytest_pytester.py	Thu Mar  5 22:01:08 2009
@@ -5,6 +5,7 @@
 import py
 from py.__.test import event
 from py.__.test.config import Config as pytestConfig
+from py.__.test.collect import Node, SetupState
 
 class PytesterPlugin:
     def pytest_pyfuncarg_linecomp(self, pyfuncitem):
@@ -132,31 +133,21 @@
         l = list(cmdlineargs) + [p]
         return self.inline_run(*l)
 
-    def inline_runsession(self, session):
-        config = session.config
-        config.pytestplugins.do_configure(config)
-        sorter = EventRecorder(config.bus)
-        session.main()
-        config.pytestplugins.do_unconfigure(config)
-        return sorter
-
     def inline_run(self, *args):
-        config = self.parseconfig(*args)
-        config.pytestplugins.do_configure(config)
-        session = config.initsession()
-        sorter = EventRecorder(config.bus)
-        session.main()
-        config.pytestplugins.do_unconfigure(config)
-        return sorter
-
-    def inline_run_with_plugins(self, *args):
-        config = self.parseconfig(*args)
-        config.pytestplugins.do_configure(config)
-        session = config.initsession()
-        sorter = EventRecorder(config.bus)
-        session.main()
-        config.pytestplugins.do_unconfigure(config)
-        return sorter
+        # for the inlined test session we should not modify 
+        # our caller's test state 
+        oldstate = Node._setupstate
+        Node._setupstate = SetupState()
+        try: 
+            config = self.parseconfig(*args)
+            config.pytestplugins.do_configure(config)
+            session = config.initsession()
+            sorter = EventRecorder(config.bus)
+            session.main()
+            config.pytestplugins.do_unconfigure(config)
+            return sorter
+        finally:
+            Node._setupstate = oldstate 
 
     def config_preparse(self):
         config = self.Config()



More information about the pytest-commit mailing list