Am 06.01.2012 12:44, schrieb Peter Otten: [running unit tests in the order of their definition]
class Loader(unittest.TestLoader): def getTestCaseNames(self, testCaseClass): """Return a sequence of method names found within testCaseClass sorted by co_firstlineno. """ def first_lineno(name): method = getattr(testCaseClass, name) return method.im_func.__code__.co_firstlinenofunction_names = super(Loader, self).getTestCaseNames(testCaseClass) function_names.sort(key=first_lineno) return function_names
After using this a bit, it works great. I have up to now only found a single problem, and that is that with decorated functions it doesn't even get at the actual line number of the real code, so sorting by that number doesn't work. An example for this is "@unittest.expectedFailure(...)".
I can easily ignore this though, just wanted to give this feedback Thanks again! Uli -- http://mail.python.org/mailman/listinfo/python-list
