2 new commits in pytest:

https://bitbucket.org/hpk42/pytest/changeset/194f44a84b46/
changeset:   194f44a84b46
user:        hpk42
date:        2012-08-08 14:53:47
summary:     also improve missing funcarg error for setup functions
affected #:  2 files

diff -r fa6a843aa98b1f8e9e95aa3b73c0bb4fcfc2e133 -r 
194f44a84b4681e1c45c7dd1b8dcf0e70d7a2e86 _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -949,9 +949,9 @@
                                                    self.parentid)
         return facdeflist
 
-    #def raiseerror(self, msg):
-    #    """ raise a FuncargLookupError with the given message. """
-    #    raise self.funcargmanager.FuncargLookupError(self.function, msg)
+    def raiseerror(self, msg):
+        """ raise a FuncargLookupError with the given message. """
+        raise self.funcargmanager.FuncargLookupError(self.function, msg)
 
     @property
     def function(self):
@@ -1375,22 +1375,26 @@
         for setupcall in setuplist:
             if setupcall.active:
                 continue
-            testcontext = TestContextSetup(request, setupcall)
-            kwargs = {}
-            for name in setupcall.funcargnames:
-                try:
-                    kwargs[name] = request.getfuncargvalue(name)
-                except FuncargLookupError:
-                    if name == "testcontext":
-                        kwargs[name] = testcontext
-                    else:
-                        raise
-            scope = setupcall.scope or "function"
-            scol = setupcall.scopeitem = request._getscopeitem(scope)
-            self.session._setupstate.addfinalizer(setupcall.finish, scol)
-            for argname in setupcall.funcargnames: # XXX all deps?
-                self.addargfinalizer(setupcall.finish, argname)
-            setupcall.execute(kwargs)
+            request._factorystack.append(setupcall)
+            try:
+                testcontext = TestContextSetup(request, setupcall)
+                kwargs = {}
+                for name in setupcall.funcargnames:
+                    try:
+                        kwargs[name] = request.getfuncargvalue(name)
+                    except FuncargLookupError:
+                        if name == "testcontext":
+                            kwargs[name] = testcontext
+                        else:
+                            raise
+                scope = setupcall.scope or "function"
+                scol = setupcall.scopeitem = request._getscopeitem(scope)
+                self.session._setupstate.addfinalizer(setupcall.finish, scol)
+                for argname in setupcall.funcargnames: # XXX all deps?
+                    self.addargfinalizer(setupcall.finish, argname)
+                setupcall.execute(kwargs)
+            finally:
+                request._factorystack.remove(setupcall)
 
     def addargfinalizer(self, finalizer, argname):
         l = self._arg2finish.setdefault(argname, [])


diff -r fa6a843aa98b1f8e9e95aa3b73c0bb4fcfc2e133 -r 
194f44a84b4681e1c45c7dd1b8dcf0e70d7a2e86 testing/test_python.py
--- a/testing/test_python.py
+++ b/testing/test_python.py
@@ -2338,21 +2338,41 @@
         reprec.assertoutcome(passed=1)
 
 
-def test_illdefined_factory(testdir):
-    testdir.makepyfile("""
-        import pytest
-        @pytest.factory()
-        def gen(request):
-            return 1
-        def test_something(gen):
-            pass
-    """)
-    result = testdir.runpytest()
-    assert result.ret != 0
-    result.stdout.fnmatch_lines([
-        "*def gen(request):*",
-        "*no factory*request*",
-    ])
+class TestErrors:
+    def test_subfactory_missing_funcarg(self, testdir):
+        testdir.makepyfile("""
+            import pytest
+            @pytest.factory()
+            def gen(request):
+                return 1
+            def test_something(gen):
+                pass
+        """)
+        result = testdir.runpytest()
+        assert result.ret != 0
+        result.stdout.fnmatch_lines([
+            "*def gen(request):*",
+            "*no factory*request*",
+            "*1 error*",
+        ])
+
+    def test_setupfunc_missing_funcarg(self, testdir):
+        testdir.makepyfile("""
+            import pytest
+            @pytest.setup()
+            def gen(request):
+                return 1
+            def test_something():
+                pass
+        """)
+        result = testdir.runpytest()
+        assert result.ret != 0
+        result.stdout.fnmatch_lines([
+            "*def gen(request):*",
+            "*no factory*request*",
+            "*1 error*",
+        ])
+
 
 class TestTestContextVarious:
     def test_newstyle_no_request(self, testdir):



https://bitbucket.org/hpk42/pytest/changeset/90a3b3d49ceb/
changeset:   90a3b3d49ceb
user:        hpk42
date:        2012-08-11 20:02:34
summary:     fix typos
affected #:  1 file

diff -r 194f44a84b4681e1c45c7dd1b8dcf0e70d7a2e86 -r 
90a3b3d49cebb9b6484251b7c7f6df1c317305d9 doc/en/funcargs.txt
--- a/doc/en/funcargs.txt
+++ b/doc/en/funcargs.txt
@@ -438,8 +438,8 @@
 this eases testing of applications which create and use global state.
 
 The following example uses two parametrized funcargs, one of which is 
-scoped on a per-module basis, and all the functions perform ``print`` call 
-it to document the flow of calls::
+scoped on a per-module basis, and all the functions perform ``print`` call s
+to show the flow of calls::
 
     # content of test_module.py
     import pytest
@@ -508,8 +508,8 @@
 
 The ``testcontext`` object may be used by `@pytest.factory`_ or
 :ref:`@pytest.setup <setup>` marked functions.  It contains
-information relating to the test context within which the function
-executes. Moreover, you can call
+information relating to the test context within which the marked
+function executes. Moreover, you can call
 ``testcontext.addfinalizer(myfinalizer)`` in order to trigger a call to
 ``myfinalizer`` after the last test in the test context has executed.
 If passed to a parametrized factory ``testcontext.param`` will contain a
@@ -693,7 +693,7 @@
 ============================================================
 
 **Funcargs** were originally introduced to pytest-2.0.  In pytest-2.3 
-the mechanism were extended and refined.  Here are some related notes:
+the mechanism was extended and refined:
 
 * previously funcarg factories were specified with a special 
   ``pytest_funcarg__NAME`` prefix instead of using the

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.
_______________________________________________
py-svn mailing list
py-svn@codespeak.net
http://codespeak.net/mailman/listinfo/py-svn

Reply via email to