As stated above, usually tests in test cases should be tested in any (i.e. random) order.
However, if you want to order tests in a test case, this is apparently not trivial. Tests (method names) are extracted from test cases using dir(MyTest) , which returns a sorted list of participants. You can use smart (?) Hacks to sort methods by their line numbers. This will work for one test case:
if __name__ == "__main__": loader = unittest.TestLoader() ln = lambda f: getattr(MyTestCase, f).im_func.func_code.co_firstlineno lncmp = lambda a, b: cmp(ln(a), ln(b)) loader.sortTestMethodsUsing = lncmp unittest.main(testLoader=loader, verbosity=2)
Udi Aug 28 '13 at 22:10 2013-08-28 22:10
source share