[TIP] TestCase.debug doesn't run tearDown in the event of an error?

Michael Foord fuzzyman at voidspace.org.uk
Wed Jul 28 06:54:03 PDT 2010


On 28/07/2010 14:46, Chris Withers wrote:
> Hi,
>
> I have some code, of which this is a minimal demonstration:
>
> from unittest import TestCase
>
> class Tests(TestCase):
>
>   def setUp(self):
>     print "setUp"
>
>   def tearDown(self):
>     print "tearDown"
>
>   def test_method(self):
>     raise ValueError('foo')
>
> tests = Tests('test_method')
>
> tests.debug()
>
> When test_method doesn't raise an exception, the tearDown is run.
> However, in the above example, the tearDown is not run.
> This is at odds with the normal unit test running experience.
> Why does debug behave differently in this respect?
>
> If it helps, this is on Python 2.5.2.

This was a design decision when TestCase.debug was first implemented - 
it simply stops on exceptions.

Michael

>
> cheers,
>
> Chris
>


-- 
http://www.ironpythoninaction.com/




More information about the testing-in-python mailing list