[py-svn] py-trunk commit ad9c92b6aca6: remove superflous building of a dict, preserve order for nodes that have identical file:lineno

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Fri Jan 15 17:52:34 CET 2010


# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User holger krekel <holger at merlinux.eu>
# Date 1263573489 -3600
# Node ID ad9c92b6aca6623367a68936c37e30b70b077178
# Parent 88f7df8ab4fbc2f5b328a16fbf106fbe297d871d
remove superflous building of a dict, preserve order for nodes that have identical file:lineno

--- a/py/_test/pycollect.py
+++ b/py/_test/pycollect.py
@@ -76,18 +76,12 @@ class PyCollectorMixin(PyobjMixin, py.te
         l = self._deprecated_collect()
         if l is not None:
             return l
-        name2items = self._buildname2items()
-        colitems = list(name2items.values())
-        colitems.sort(key=lambda item: item.reportinfo()[:2])
-        return colitems
-
-    def _buildname2items(self): 
         # NB. we avoid random getattrs and peek in the __dict__ instead
-        d = {}
         dicts = [getattr(self.obj, '__dict__', {})]
         for basecls in inspect.getmro(self.obj.__class__):
             dicts.append(basecls.__dict__)
         seen = {}
+        l = []
         for dic in dicts:
             for name, obj in dic.items():
                 if name in seen:
@@ -96,8 +90,9 @@ class PyCollectorMixin(PyobjMixin, py.te
                 if name[0] != "_":
                     res = self.makeitem(name, obj)
                     if res is not None:
-                        d[name] = res 
-        return d
+                        l.append(res)
+        l.sort(key=lambda item: item.reportinfo()[:2])
+        return l
 
     def _deprecated_join(self, name):
         if self.__class__.join != py.test.collect.Collector.join:

--- a/testing/test_pycollect.py
+++ b/testing/test_pycollect.py
@@ -333,7 +333,7 @@ class TestConftestCustomization:
         l = []
         monkeypatch.setattr(py.test.collect.Module, 'makeitem', 
             lambda self, name, obj: l.append(name))
-        modcol._buildname2items()
+        l = modcol.collect()
         assert '_hello' not in l



More information about the pytest-commit mailing list