[Tutor] unittest testing order...

Evert Rol evert.rol at gmail.com
Mon Sep 27 21:16:37 CEST 2010


>> List,
>> 
>> When using the unittest module, tests are run in alphanumeric order.
>> What's the suggested way of specifying a test order? 
> 
> There isn't one. It shouldn't matter what order the tests run, no test 
> should *rely* on another test. 
> 
> (Although of course, if one test fails, any tests which assume the 
> missing functionality will also fail.)

Steven is right that unittests should be independent. 

I did once, however, come across an option to order the tests. Scanning through the unittest docs, I found "sortTestMethodsUsing":

"Function to be used to compare method names when sorting them in getTestCaseNames() and all the loadTestsFrom*() methods. The default value is the built-in cmp() function; the attribute can also be set to None to disable the sort."

Perhaps that does what you want. But I would indeed not recommend it.

  Evert



More information about the Tutor mailing list