# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User holger krekel <hol...@merlinux.eu>
# Date 1263574202 -3600
# Node ID 1464edd0ddb6477d14537505db642e80e1ceb1a2
# Parent ad9c92b6aca6623367a68936c37e30b70b077178
get rid of the funccollector node, which nice-ifies names of funcarg-generated 
tests nodes, also test and fix one anomaly wrt to funcarg setups and instance 
uniqueness

--- a/py/_test/funcargs.py
+++ b/py/_test/funcargs.py
@@ -60,31 +60,6 @@ class Metafunc:
         self._ids.add(id)
         self._calls.append(CallSpec(funcargs, id, param))
 
-class FunctionCollector(py.test.collect.Collector):
-    def __init__(self, name, parent, calls):
-        super(FunctionCollector, self).__init__(name, parent)
-        self.calls = calls 
-        self.obj = getattr(self.parent.obj, name) 
-       
-    def collect(self):
-        l = []
-        for callspec in self.calls:
-            name = "%s[%s]" %(self.name, callspec.id)
-            function = self.parent.Function(name=name, parent=self, 
-                callspec=callspec, callobj=self.obj)
-            l.append(function)
-        return l
-
-    def reportinfo(self):
-        try:
-            return self._fslineno, self.name
-        except AttributeError:
-            pass        
-        fspath, lineno = py.code.getfslineno(self.obj)
-        self._fslineno = fspath, lineno
-        return fspath, lineno, self.name
-    
-
 class FuncargRequest:
     _argprefix = "pytest_funcarg__"
     _argname = None

--- a/py/_test/pycollect.py
+++ b/py/_test/pycollect.py
@@ -89,8 +89,11 @@ class PyCollectorMixin(PyobjMixin, py.te
                 seen[name] = True
                 if name[0] != "_":
                     res = self.makeitem(name, obj)
-                    if res is not None:
-                        l.append(res)
+                    if res is None:
+                        continue
+                    if not isinstance(res, list):
+                        res = [res]
+                    l.extend(res)
         l.sort(key=lambda item: item.reportinfo()[:2])
         return l
 
@@ -122,9 +125,13 @@ class PyCollectorMixin(PyobjMixin, py.te
         gentesthook.pcall(plugins, metafunc=metafunc)
         if not metafunc._calls:
             return self.Function(name, parent=self)
-        return funcargs.FunctionCollector(name=name, 
-            parent=self, calls=metafunc._calls)
-
+        l = []
+        for callspec in metafunc._calls:
+            subname = "%s[%s]" %(name, callspec.id)
+            function = self.Function(name=subname, parent=self, 
+                callspec=callspec, callobj=funcobj)
+            l.append(function)
+        return l
         
 class Module(py.test.collect.File, PyCollectorMixin):
     def _getobj(self):
@@ -313,6 +320,13 @@ class Function(FunctionMixin, py.test.co
             self._obj = callobj 
         self.function = getattr(self.obj, 'im_func', self.obj)
 
+    def _getobj(self):
+        name = self.name
+        i = name.find("[") # parametrization
+        if i != -1:
+            name = name[:i]
+        return getattr(self.parent.obj, name)
+
     def _isyieldedfunction(self):
         return self._args is not None
 

--- a/doc/example/assertion/test_failures.py
+++ b/doc/example/assertion/test_failures.py
@@ -11,4 +11,4 @@ def test_failure_demo_fails_properly(tes
     assert failed == 20, failed
     colreports = reprec.getreports("pytest_collectreport")
     failed = len([x.failed for x in colreports])
-    assert failed == 4
+    assert failed == 3

--- a/testing/test_funcargs.py
+++ b/testing/test_funcargs.py
@@ -498,6 +498,24 @@ class TestGenfuncFunctional:
             "*1 passed*"
         ])
 
+    def test_two_functions_not_same_instance(self, testdir):
+        p = testdir.makepyfile("""
+            def pytest_generate_tests(metafunc):
+                metafunc.addcall({'arg1': 10})
+                metafunc.addcall({'arg1': 20})
+
+            class TestClass:
+                def test_func(self, arg1):
+                    assert not hasattr(self, 'x')
+                    self.x = 1
+        """)
+        result = testdir.runpytest("-v", p)
+        assert result.stdout.fnmatch_lines([
+            "*test_func*0*PASS*", 
+            "*test_func*1*PASS*", 
+            "*2 pass*",
+        ])
+
 
 def test_conftest_funcargs_only_available_in_subdir(testdir):
     sub1 = testdir.mkpydir("sub1")
_______________________________________________
py-svn mailing list
py-svn@codespeak.net
http://codespeak.net/mailman/listinfo/py-svn

Reply via email to