[py-svn] r64306 - in py/trunk: contrib/pytest_twisted py/test py/test/dist py/test/plugin py/test/testing

hpk at codespeak.net hpk at codespeak.net
Fri Apr 17 20:32:30 CEST 2009


Author: hpk
Date: Fri Apr 17 20:32:26 2009
New Revision: 64306

Added:
   py/trunk/py/test/testing/test_api.py
Modified:
   py/trunk/contrib/pytest_twisted/__init__.py
   py/trunk/py/test/config.py
   py/trunk/py/test/dist/dsession.py
   py/trunk/py/test/plugin/api.py
   py/trunk/py/test/pluginmanager.py
   py/trunk/py/test/runner.py
   py/trunk/py/test/testing/acceptance_test.py
   py/trunk/py/test/testing/test_pluginmanager.py
Log:
merging hg py-trunk to svn py-trunk.


Modified: py/trunk/contrib/pytest_twisted/__init__.py
==============================================================================
--- py/trunk/contrib/pytest_twisted/__init__.py	(original)
+++ py/trunk/contrib/pytest_twisted/__init__.py	Fri Apr 17 20:32:26 2009
@@ -100,18 +100,13 @@
 
     def pytest_pyfunc_call(self, pyfuncitem, *args, **kwargs):
         if self.twisted:
-            def wrapper(func):
-                """
-                wrapper just to pass back (injecting) the test-function into
-                doit() by using a greenlet switch.
-                """
-                if hasattr(func, 'obj'):
-                    # XXX: what about **kwargs?
-                    res = gr_twisted.switch(lambda: func.obj(*args))
-                    if res:
-                        res.raiseException()
-            pyfuncitem = wrapper(pyfuncitem)    
-
+            # XXX1 kwargs?  
+            # XXX2 we want to delegate actual call to next plugin
+            #      (which may want to produce test coverage, etc.) 
+            res = gr_twisted.switch(lambda: pyfuncitem.obj(*args))
+            if res:
+                res.raiseException()
+            return True # indicates that we performed the function call 
 
 gr_twisted  = greenlet(_run_twisted)
 gr_tests    = greenlet.getcurrent()

Modified: py/trunk/py/test/config.py
==============================================================================
--- py/trunk/py/test/config.py	(original)
+++ py/trunk/py/test/config.py	Fri Apr 17 20:32:26 2009
@@ -76,6 +76,7 @@
 
     def _preparse(self, args):
         self._conftest.setinitial(args) 
+        self.pluginmanager.consider_preparse(args)
         self.pluginmanager.consider_env()
         self.pluginmanager.do_addoption(self._parser)
 

Modified: py/trunk/py/test/dist/dsession.py
==============================================================================
--- py/trunk/py/test/dist/dsession.py	(original)
+++ py/trunk/py/test/dist/dsession.py	Fri Apr 17 20:32:26 2009
@@ -203,7 +203,7 @@
         tosend[:] = tosend[room:]  # update inplace
         if tosend:
             # we have some left, give it to the main loop
-            self.queueevent(pytest_rescheduleitems, tosend)
+            self.queueevent("pytest_rescheduleitems", items=tosend)
 
     def senditems_load(self, tosend):
         if not tosend:

Modified: py/trunk/py/test/plugin/api.py
==============================================================================
--- py/trunk/py/test/plugin/api.py	(original)
+++ py/trunk/py/test/plugin/api.py	Fri Apr 17 20:32:26 2009
@@ -69,6 +69,7 @@
 
     def pytest_pyfunc_call(self, pyfuncitem, args, kwargs):
         """ return True if we consumed/did the call to the python function item. """
+    pytest_pyfunc_call.firstresult = True
 
     def pytest_item_makereport(self, item, excinfo, when, outerr):
         """ return ItemTestReport for the given test outcome. """

Modified: py/trunk/py/test/pluginmanager.py
==============================================================================
--- py/trunk/py/test/pluginmanager.py	(original)
+++ py/trunk/py/test/pluginmanager.py	Fri Apr 17 20:32:26 2009
@@ -47,6 +47,11 @@
         for spec in self._envlist("PYTEST_PLUGINS"):
             self.import_plugin(spec)
 
+    def consider_preparse(self, args):
+        for opt1,opt2 in zip(args, args[1:]):
+            if opt1 == "-p": 
+                self.import_plugin(opt2)
+
     def consider_conftest(self, conftestmodule):
         cls = getattr(conftestmodule, 'ConftestPlugin', None)
         if cls is not None and cls not in self.impname2plugin:

Modified: py/trunk/py/test/runner.py
==============================================================================
--- py/trunk/py/test/runner.py	(original)
+++ py/trunk/py/test/runner.py	Fri Apr 17 20:32:26 2009
@@ -53,8 +53,6 @@
         excinfo = py.code.ExceptionInfo()
     return CollectReport(collector, res, excinfo, outerr)
 
-from cPickle import Pickler, Unpickler
-
 def forked_run_report(item, pdb=None):
     EXITSTATUS_TESTEXIT = 4
     from py.__.test.dist.mypickle import ImmutablePickler

Modified: py/trunk/py/test/testing/acceptance_test.py
==============================================================================
--- py/trunk/py/test/testing/acceptance_test.py	(original)
+++ py/trunk/py/test/testing/acceptance_test.py	Fri Apr 17 20:32:26 2009
@@ -17,6 +17,23 @@
             '*ERROR: hello'
         ])
 
+    def test_config_preparse_plugin_option(self, testdir):
+        testdir.makepyfile(pytest_xyz="""
+            class XyzPlugin:
+                def pytest_addoption(self, parser):
+                    parser.addoption("--xyz", dest="xyz", action="store")
+        """)
+        testdir.makepyfile(test_one="""
+            import py
+            def test_option():
+                assert py.test.config.option.xyz == "123"
+        """)
+        result = testdir.runpytest("-p", "xyz", "--xyz=123")
+        assert result.ret == 0
+        assert result.stdout.fnmatch_lines([
+            '*1 passed*',
+        ])
+
     def test_basetemp(self, testdir):
         mytemp = testdir.tmpdir.mkdir("mytemp")
         p = testdir.makepyfile("""

Added: py/trunk/py/test/testing/test_api.py
==============================================================================
--- (empty file)
+++ py/trunk/py/test/testing/test_api.py	Fri Apr 17 20:32:26 2009
@@ -0,0 +1,14 @@
+
+class TestPyfuncHooks:
+    def test_pyfunc_call(self, testdir):
+        item = testdir.getitem("def test_func(): raise ValueError")
+        config = item.config
+        class MyPlugin1:
+            def pytest_pyfunc_call(self, pyfuncitem, *args, **kwargs):
+                raise ValueError
+        class MyPlugin2:
+            def pytest_pyfunc_call(self, pyfuncitem, *args, **kwargs):
+                return True
+        config.pluginmanager.register(MyPlugin1())
+        config.pluginmanager.register(MyPlugin2())
+        config.api.pytest_pyfunc_call(pyfuncitem=item)

Modified: py/trunk/py/test/testing/test_pluginmanager.py
==============================================================================
--- py/trunk/py/test/testing/test_pluginmanager.py	(original)
+++ py/trunk/py/test/testing/test_pluginmanager.py	Fri Apr 17 20:32:26 2009
@@ -8,6 +8,12 @@
         monkeypatch.setitem(os.environ, 'PYTEST_PLUGINS', 'nonexistingmodule')
         py.test.raises(ImportError, "pluginmanager.consider_env()")
 
+    def test_preparse_args(self, monkeypatch):
+        pluginmanager = PluginManager()
+        py.test.raises(ImportError, """
+            pluginmanager.consider_preparse(["xyz", "-p", "hello123"])
+        """)
+
     def test_consider_env_plugin_instantiation(self, testdir, monkeypatch):
         pluginmanager = PluginManager()
         testdir.syspathinsert()



More information about the pytest-commit mailing list