[py-svn] commit/pytest: hpk42: remove unneccessary internal __request__ funcarg.

Bitbucket commits-noreply at bitbucket.org
Mon Oct 1 09:23:59 CEST 2012


1 new commit in pytest:


https://bitbucket.org/hpk42/pytest/changeset/8a116c6b207a/
changeset:   8a116c6b207a
user:        hpk42
date:        2012-10-01 09:23:39
summary:     remove unneccessary internal __request__ funcarg.
affected #:  2 files

diff -r 1f79503ce1f8a68185c7f8b2900546fb84606adb -r 8a116c6b207a0b4fa75eb690fee7b2a8c07631ce _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -519,11 +519,8 @@
 
 
 def fillfuncargs(function):
-    """ fill missing funcargs. """
-    #if not getattr(function, "_args", None) is not None:
-    #    request = FuncargRequest(pyfuncitem=function)
-    #    request._fillfuncargs()
-    if getattr(function, "_args", None) is None:
+    """ fill missing funcargs for a test function. """
+    if getattr(function, "_args", None) is None:  # not a yielded function
         try:
             request = function._request
         except AttributeError:
@@ -941,11 +938,6 @@
         return property(provide, None, None, func.__doc__)
     return decoratescope
 
-def pytest_funcarg__request(__request__):
-    return __request__
-
-#def pytest_funcarg__testcontext(__request__):
-#    return __request__
 
 class FuncargRequest:
     """ A request for function arguments from a test or setup function.
@@ -963,7 +955,6 @@
         self.scope = "function"
         self.getparent = pyfuncitem.getparent
         self._funcargs  = self._pyfuncitem.funcargs.copy()
-        self._funcargs["__request__"] = self
         self._name2factory = {}
         self.funcargmanager = pyfuncitem.session.funcargmanager
         self._currentarg = None
@@ -1078,9 +1069,6 @@
     def _fillfuncargs(self):
         item = self._pyfuncitem
         funcargnames = getattr(item, "funcargnames", self.funcargnames)
-        if funcargnames:
-            assert not getattr(item, '_args', None), (
-                "yielded functions cannot have funcargs")
         for argname in funcargnames:
             if argname not in item.funcargs:
                 item.funcargs[argname] = self.getfuncargvalue(argname)
@@ -1128,23 +1116,28 @@
 
 
     def getfuncargvalue(self, argname):
-        """ (deprecated) Retrieve a function argument by name for this test
+        """ Retrieve a function argument by name for this test
         function invocation.  This allows one function argument factory
         to call another function argument factory.  If there are two
         funcarg factories for the same test function argument the first
         factory may use ``getfuncargvalue`` to call the second one and
         do something additional with the resource.
 
-        **Note**, however, that starting with
-        pytest-2.3 it is easier and better to directly state the needed
-        funcarg in the factory signature.  This will also work seemlessly
+        **Note**, however, that starting with pytest-2.3 it is usually
+        easier and better to directly use the needed funcarg in the
+        factory function signature.  This will also work seemlessly
         with parametrization and the new resource setup optimizations.
         """
         try:
             return self._funcargs[argname]
         except KeyError:
             pass
-        factorydeflist = self._getfaclist(argname)
+        try:
+            factorydeflist = self._getfaclist(argname)
+        except FuncargLookupError:
+            if argname == "request":
+                return self
+            raise
         factorydef = factorydeflist.pop()
         self._factorystack.append(factorydef)
         try:
@@ -1338,10 +1331,6 @@
                 if facdeflist is not None:
                     for facdef in facdeflist:
                         merge(facdef.funcargnames)
-        try:
-            funcargnames.remove("__request__")
-        except ValueError:
-            pass
         return funcargnames, arg2facdeflist
 
     def pytest_generate_tests(self, metafunc):


diff -r 1f79503ce1f8a68185c7f8b2900546fb84606adb -r 8a116c6b207a0b4fa75eb690fee7b2a8c07631ce testing/test_python.py
--- a/testing/test_python.py
+++ b/testing/test_python.py
@@ -1758,7 +1758,6 @@
             "*LookupError: no factory found for argument 'missing'",
         ])
 
-
     def test_factory_setup_as_classes(self, testdir):
         testdir.makepyfile("""
             import pytest
@@ -1779,6 +1778,19 @@
         reprec = testdir.inline_run()
         reprec.assertoutcome(passed=1)
 
+    def test_request_can_be_overridden(self, testdir):
+        testdir.makepyfile("""
+            import pytest
+            @pytest.factory()
+            def request(request):
+                request.a = 1
+                return request
+            def test_request(request):
+                assert request.a == 1
+        """)
+        reprec = testdir.inline_run()
+        reprec.assertoutcome(passed=1)
+
 
 class TestResourceIntegrationFunctional:
     def test_parametrize_with_ids(self, testdir):
@@ -2661,18 +2673,7 @@
     reprec = testdir.inline_run()
     reprec.assertoutcome(passed=3)
 
-def test_request_can_be_overridden(testdir):
-    testdir.makepyfile("""
-        import pytest
-        @pytest.factory()
-        def request(request):
-            request.a = 1
-            return request
-        def test_request(request):
-            assert request.a == 1
-    """)
-    reprec = testdir.inline_run()
-    reprec.assertoutcome(passed=1)
+
 
 def test_setup_funcarg_order(testdir):
     testdir.makepyfile("""

Repository URL: https://bitbucket.org/hpk42/pytest/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the pytest-commit mailing list