[py-svn] commit/pytest: 2 new changesets

Bitbucket commits-noreply at bitbucket.org
Tue Sep 18 14:01:00 CEST 2012


2 new commits in pytest:


https://bitbucket.org/hpk42/pytest/changeset/b23ae4aae78b/
changeset:   b23ae4aae78b
user:        hpk42
date:        2012-09-18 13:46:24
summary:     fix bug introduced with last checkin
affected #:  1 file

diff -r 93f393567640808a5c6166fe618adf38e37890d4 -r b23ae4aae78bdb1d5ab9fca35e41f7bcb64dd8d6 _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -1469,7 +1469,8 @@
         self.funcargmanager = funcargmanager
         self.baseid = baseid
         self.func = func
-        self.funcargnames = getfuncargnames(func, startindex=int(unittest))
+        startindex = unittest and 1 or None
+        self.funcargnames = getfuncargnames(func, startindex=startindex)
         self.scope = scope
         self.scopenum = scopes.index(scope)
         self.active = False



https://bitbucket.org/hpk42/pytest/changeset/32885e1d2189/
changeset:   32885e1d2189
user:        hpk42
date:        2012-09-18 14:00:47
summary:     allow factory/setup-markers on classes, using their respective __init__ methods which can use the funcarg mechanism
affected #:  3 files

diff -r b23ae4aae78bdb1d5ab9fca35e41f7bcb64dd8d6 -r 32885e1d2189b3bbedfe1a5951c5e1560590d6fe _pytest/python.py
--- a/_pytest/python.py
+++ b/_pytest/python.py
@@ -1507,9 +1507,12 @@
 
 def getfuncargnames(function, startindex=None):
     # XXX merge with main.py's varnames
-    argnames = py.std.inspect.getargs(py.code.getrawcode(function))[0]
-    if startindex is None:
-        startindex = py.std.inspect.ismethod(function) and 1 or 0
+    if inspect.isclass(function):
+        function = function.__init__
+        startindex = 1
+    elif startindex is None:
+        startindex = inspect.ismethod(function) and 1 or 0
+    argnames = inspect.getargs(py.code.getrawcode(function))[0]
     defaults = getattr(function, 'func_defaults',
                        getattr(function, '__defaults__', None)) or ()
     numdefaults = len(defaults)


diff -r b23ae4aae78bdb1d5ab9fca35e41f7bcb64dd8d6 -r 32885e1d2189b3bbedfe1a5951c5e1560590d6fe doc/en/funcargs.txt
--- a/doc/en/funcargs.txt
+++ b/doc/en/funcargs.txt
@@ -389,19 +389,16 @@
    
     import pytest
 
-    class App:
+    @pytest.factory(scope="module")
+    class app:
         def __init__(self, smtp):
             self.smtp = smtp
 
-    @pytest.factory(scope="module")
-    def app(smtp):
-        return App(smtp)
-
     def test_exists(app):
         assert app.smtp
 
-Here we define the factory local to the test module and make it access
-the ``smtp`` resource by listing it as an input parameter.  Let's run this::
+Here we declare an ``app`` class to be a factory and have its init-method
+use the previously defined ``smtp`` resource.  Let's run it::
 
     $ py.test -v test_appsetup.py
     =========================== test session starts ============================
@@ -418,7 +415,7 @@
 Due to the parametrization of ``smtp`` the test will run twice with two
 different ``App`` instances and respective smtp servers.  There is no
 need for the ``app`` factory to be aware of the parametrization.  Note
-that the ``app`` factory has a scope of ``module`` whereas it uses the
+that the ``app`` factory has a scope of ``module`` but uses the
 session-scoped ``smtp`` object: it is fine for factories to use
 "broader" scoped resources but not the other way round.  A
 session-scoped resource could not use a module-scoped resource in a
@@ -498,8 +495,8 @@
     fin mod2
 
 You can see that the parametrized module-scoped ``modarg`` resource caused
-a re-ordering of test execution. The finalizer for the ``mod1`` parametrized 
-resource was executed before the ``mod2`` resource was setup.
+an ordering of test execution that lead to the fewest possible "active" resources. The finalizer for the ``mod1`` parametrized resource was executed 
+before the ``mod2`` resource was setup.
 
 .. currentmodule:: _pytest.python
 .. _`request`:
@@ -520,7 +517,6 @@
 * to add finalizers/teardowns to be invoked when the last
   test of the requesting test context executes
 
-
 .. autoclass:: _pytest.python.FuncargRequest()
     :members:
 


diff -r b23ae4aae78bdb1d5ab9fca35e41f7bcb64dd8d6 -r 32885e1d2189b3bbedfe1a5951c5e1560590d6fe testing/test_python.py
--- a/testing/test_python.py
+++ b/testing/test_python.py
@@ -535,6 +535,11 @@
     if sys.version_info < (3,0):
         assert funcargs.getfuncargnames(A.f) == ['arg1']
 
+    class A:
+        def __init__(self, x):
+            pass
+    assert funcargs.getfuncargnames(A) == ["x"]
+
 class TestFillFuncArgs:
     def test_fillfuncargs_exposed(self):
         # used by oejskit
@@ -1727,6 +1732,26 @@
         ])
 
 
+    def test_factory_setup_as_classes(self, testdir):
+        testdir.makepyfile("""
+            import pytest
+            class arg1:
+                def __init__(self, request):
+                    self.x = 1
+            arg1 = pytest.factory()(arg1)
+
+            class MySetup:
+                def __init__(self, request, arg1):
+                    request.instance.arg1 = arg1
+            pytest.setup()(MySetup)
+
+            class TestClass:
+                def test_method(self):
+                    assert self.arg1.x == 1
+        """)
+        reprec = testdir.inline_run()
+        reprec.assertoutcome(passed=1)
+
 
 class TestResourceIntegrationFunctional:
     def test_parametrize_with_ids(self, testdir):

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