[TIP] Functions for tests instead of classes

Mark Sienkiewicz sienkiew at stsci.edu
Mon Mar 15 11:21:01 PDT 2010


Michael Foord wrote:
> On 15/03/2010 17:46, Pekka Klärck wrote:
>> [snip...]
>>> Then, to retain compatibility with older versions of unittest, the 
>>> TestCase
>>> object can contain a bunch of trivial methods like:
>>>
>>>    def assertEqual(self, a, b) :
>>>       return assertEqual(a,b)
>>>      
>> Yep, keeping backwards compatibility would be trivial. Are there any
>> good reasons not to do this?
>>    
>
> Per TestCase failureException is one reason.

I don't understand what you mean.  (Or maybe, I do understand, but I 
don't see how it is a problem.)

You could have a module full of friendly assert functions, but if you 
need a custom assert function for your object, you can still have one.  
After all, if your test contains a special assertEqual, you are going to 
have to override the assertEqual in the base class -- i.e. you write 
your own anyway.

Mark S.




More information about the testing-in-python mailing list