[TIP] cleanUp for unittest
Michael Foord
fuzzyman at voidspace.org.uk
Fri Apr 3 10:47:39 PDT 2009
Laura Creighton wrote:
> In a message of Fri, 03 Apr 2009 18:08:58 BST, Michael Foord writes:
>
>> Hello all,
>>
>> There is a feature request for unittest that we add a 'cleanUp' list.
>>
>> This is a list of functions to call on exit of a test that can be added
>> to in setUp or during test execution. The difference between this and
>> tearDown is that if anything is in the cleanUp list they will be called
>> *even* if setUp fails (which normally means tearDown is skipped).
>>
>> Is there consensus that adding this to unittest is a good thing? If
>> there is then I will just do it...
>>
>> Should it be done before or after calling tearDown? I don't think it
>> matters so long as it is documented.
>>
>> Michael Foord
>>
>> --
>> http://www.ironpythoninaction.com/
>> http://www.voidspace.org.uk/blog
>>
>
> Cleanup should run after tearDown, since then it can clean up after a
> failed tearDown, too. I'm not so happy with cleanup being a list of functions.
> What's wrong with overriding it in a subclass, same as tearDown?
>
See the example code posted by Kumar - and the clean way it enables you
to add new cleanup items without having to track how far your test /
setUp code got before it died.
Michael
> puzzled,
> Laura
>
--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog
More information about the testing-in-python
mailing list