diff --git a/py/test/collect.py b/py/test/collect.py index 31eb30970..7726c4ee0 100644 --- a/py/test/collect.py +++ b/py/test/collect.py @@ -79,13 +79,6 @@ class Node(object): def __hash__(self): return hash((self.name, self.parent)) - - def __cmp__(self, other): - if not isinstance(other, Node): - return -1 - s1 = self._getsortvalue() - s2 = other._getsortvalue() - return cmp(s1, s2) def setup(self): pass @@ -230,9 +223,6 @@ class Node(object): return True return False - def _getsortvalue(self): - return self.name - def _prunetraceback(self, traceback): return traceback diff --git a/py/test/funcargs.py b/py/test/funcargs.py index 2d022cfab..ef70b442e 100644 --- a/py/test/funcargs.py +++ b/py/test/funcargs.py @@ -64,7 +64,17 @@ class FunctionCollector(py.test.collect.Collector): function = self.parent.Function(name=name, parent=self, callspec=callspec, callobj=self.obj) l.append(function) - return l + 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__" diff --git a/py/test/pycollect.py b/py/test/pycollect.py index 420ef1dac..620d39a7d 100644 --- a/py/test/pycollect.py +++ b/py/test/pycollect.py @@ -93,7 +93,7 @@ class PyCollectorMixin(PyobjMixin, py.test.collect.Collector): return l name2items = self._buildname2items() colitems = name2items.values() - colitems.sort() + colitems.sort(key=lambda item: item.reportinfo()[:2]) return colitems def _buildname2items(self): @@ -205,9 +205,6 @@ class Class(PyCollectorMixin, py.test.collect.Collector): teardown_class = getattr(teardown_class, 'im_func', teardown_class) teardown_class(self.obj) - def _getsortvalue(self): - return self._getfslineno() - class Instance(PyCollectorMixin, py.test.collect.Collector): def _getobj(self): return self.parent.obj() @@ -230,9 +227,6 @@ class FunctionMixin(PyobjMixin): """ mixin for the code common to Function and Generator. """ - def _getsortvalue(self): - return self._getfslineno() - def setup(self): """ perform setup for this test function. """ if hasattr(self.obj, 'im_self'): diff --git a/py/test/testing/test_collect.py b/py/test/testing/test_collect.py index 0d1d3112f..544df1fa4 100644 --- a/py/test/testing/test_collect.py +++ b/py/test/testing/test_collect.py @@ -6,7 +6,7 @@ class TestCollector: assert not issubclass(Collector, Item) assert not issubclass(Item, Collector) - def test_check_equality_and_cmp_basic(self, testdir): + def test_check_equality(self, testdir): modcol = testdir.getmodulecol(""" def test_pass(): pass def test_fail(): assert 0 @@ -25,11 +25,7 @@ class TestCollector: assert isinstance(fn3, py.test.collect.Function) assert not (fn1 == fn3) assert fn1 != fn3 - assert cmp(fn1, fn3) == -1 - assert cmp(fn1, 10) == -1 - assert cmp(fn2, 10) == -1 - assert cmp(fn3, 10) == -1 for fn in fn1,fn2,fn3: assert fn != 3 assert fn != modcol diff --git a/py/test/testing/test_pycollect.py b/py/test/testing/test_pycollect.py index a4fe30538..0412ce3c9 100644 --- a/py/test/testing/test_pycollect.py +++ b/py/test/testing/test_pycollect.py @@ -269,7 +269,7 @@ class TestFunction: assert not (f5 == f5b) class TestSorting: - def test_check_equality_and_cmp_basic(self, testdir): + def test_check_equality(self, testdir): modcol = testdir.getmodulecol(""" def test_pass(): pass def test_fail(): assert 0 @@ -288,11 +288,7 @@ class TestSorting: assert isinstance(fn3, py.test.collect.Function) assert not (fn1 == fn3) assert fn1 != fn3 - assert cmp(fn1, fn3) == -1 - assert cmp(fn1, 10) == -1 - assert cmp(fn2, 10) == -1 - assert cmp(fn3, 10) == -1 for fn in fn1,fn2,fn3: assert fn != 3 assert fn != modcol @@ -308,18 +304,18 @@ class TestSorting: return g - def test_a(y): - pass - test_a = dec(test_a) - def test_b(y): pass test_b = dec(test_b) + + def test_a(y): + pass + test_a = dec(test_a) """) colitems = modcol.collect() assert len(colitems) == 2 - f1, f2 = colitems - assert cmp(f2, f1) > 0 + assert [item.name for item in colitems] == ['test_b', 'test_a'] + class TestConftestCustomization: def test_extra_python_files_and_functions(self, testdir):