[py-svn] r35502 - py/dist/py/test

arigo at codespeak.net arigo at codespeak.net
Fri Dec 8 19:00:03 CET 2006


Author: arigo
Date: Fri Dec  8 19:00:00 2006
New Revision: 35502

Modified:
   py/dist/py/test/collect.py
Log:
Try harder to order the classes.  Now they should really
have the ordering they have in their source file.


Modified: py/dist/py/test/collect.py
==============================================================================
--- py/dist/py/test/collect.py	(original)
+++ py/dist/py/test/collect.py	Fri Dec  8 19:00:00 2006
@@ -425,12 +425,16 @@
             teardown_class(self.obj) 
 
     def getsortvalue(self):
+        # try to locate the class in the source - not nice, but probably
+        # the most useful "solution" that we have
         try:
-            for key, val in self.obj.__dict__.iteritems():
-                import types
-                if type(val) is (types.FunctionType, types.GeneratorType):
-                    return val.func_code.co_firstlineno
-        except AttributeError:
+            file = (py.std.inspect.getsourcefile(self.obj) or
+                    py.std.inspect.getfile(self.obj))
+            if not file:
+                raise IOError
+            lines, lineno = py.std.inspect.findsource(self.obj)
+            return py.path.local(file), lineno
+        except IOError:
             pass
         # fall back...
         for x in self.tryiter((py.test.collect.Generator, py.test.Item)):



More information about the pytest-commit mailing list