[TIP] Functions for tests instead of classes

Mark Sienkiewicz sienkiew at stsci.edu
Wed Mar 17 12:35:00 PDT 2010


>> Using the "special object" that you mentioned some time ago, that 
>> could be
>>
>> from unittest2 import assertions
>> # assertions is a TestCase object that contains no tests, but it is 
>> not in this namespace
>> # so no test runners will detect it when we run the tests in this file
>>
>> def test() :
>>    ...
>>    assertions.assertEqual(a,b)
>>
>
> I fail to see any advantage (beyond extra typing) over 
> self.assertEqual(a, b).


If your test is a function, there is no "self".





More information about the testing-in-python mailing list