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

Chris Withers chris at simplistix.co.uk
Wed Jul 28 06:46:17 PDT 2010


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')


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.



Simplistix - Content Management, Batch Processing & Python Consulting
            - http://www.simplistix.co.uk

More information about the testing-in-python mailing list