replacing __dict__ with an OrderedDict
Ulrich Eckhardt
ulrich.eckhardt at dominolaser.com
Wed Jan 18 05:29:55 EST 2012
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_firstlineno
>
> function_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
More information about the Python-list
mailing list