unittest: Calling tests in liner number order

Antoon Pardon apardon at forel.vub.ac.be
Fri May 23 05:36:40 EDT 2008


Some time ago I asked whether is would be possible that unittest would
perform the test in order of appearence in the file.

The answers seemed to be negative. Since I really would like this
behaviour I took the trouble of looking throught the source and
I think I found a minor way to get this behaviour.

Now my questions are:

Are other people interrested in this behaviour?
Does the following patch has a chance of being introduced in the
standard python distribution?

*** /usr/lib/python2.5/unittest.py      2008-04-17 16:26:37.000000000 +0200
--- unittest.py 2008-05-23 11:19:57.000000000 +0200
***************
*** 570,575 ****
--- 570,577 ----
          """
          def isTestMethod(attrname, testCaseClass=testCaseClass, prefix=self.testMethodPrefix):
              return attrname.startswith(prefix) and callable(getattr(testCaseClass, attrname))
+         def getlinenr(name):
+             return getattr(testCaseClass, name).im_func.func_code.co_firstlineno
          testFnNames = filter(isTestMethod, dir(testCaseClass))
          for baseclass in testCaseClass.__bases__:
              for testFnName in self.getTestCaseNames(baseclass):
***************
*** 577,582 ****
--- 579,586 ----
                      testFnNames.append(testFnName)
          if self.sortTestMethodsUsing:
              testFnNames.sort(self.sortTestMethodsUsing)
+         else:
+             testFnNames.sort(key=getlinenr)
          return testFnNames
  




More information about the Python-list mailing list