From ee2f292efaa2dc7dfedca481fea7ee173815d1b6 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Fri, 15 Jan 2010 17:38:09 +0100 Subject: [PATCH] remove superflous building of a dict, preserve order for nodes that have identical file:lineno --HG-- branch : trunk --- py/_test/pycollect.py | 13 ++++--------- testing/test_pycollect.py | 2 +- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/py/_test/pycollect.py b/py/_test/pycollect.py index db4094915..e8c1c7ce1 100644 --- a/py/_test/pycollect.py +++ b/py/_test/pycollect.py @@ -76,18 +76,12 @@ class PyCollectorMixin(PyobjMixin, py.test.collect.Collector): 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.test.collect.Collector): 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: diff --git a/testing/test_pycollect.py b/testing/test_pycollect.py index 0b67384ec..5a3b268aa 100644 --- 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