[Python-Dev] Questions on unittest behaviour (original) (raw)

Jonathan Lange jml at mumak.net
Sat Aug 19 08:36:48 CEST 2006


On 8/19/06, Collin Winter <collinw at gmail.com> wrote:

1) TestCase.tearDown() is only run if TestCase.setUp() succeeded. It seems to me that tearDown() should always be run, regardless of any failures in setUp() or the test method itself.

The case I'm considering is something like this, ie, a multi-part setUp(): > def setUp(self) > lockfile(testfile) # opensocket(), connecttodatabase(), etc > > somethingthatraisesanexception() > > def tearDown(self): > if fileislocked(testfile): > unlockfile(testfile) I'm undecided if this is a new feature (so it should go in for 2.6) or a bug fix; I'm leaning toward the latter.

Most existing tearDown() code assumes that setUp() has been successfully called -- after all, that's what the docs say. It's also the behaviour of other xUnit frameworks.

If this change is made, people will have to go through their tearDown() methods and add checks like the one in your example in order to make their tests correct. Further, it won't be obvious that their tearDown() methods are incorrect until something happens to make their setUp() methods incorrect.

I don't think this change is a good one. However, if it does go in, it definitely shouldn't go in as a bug fix.

cheers, jml



More information about the Python-Dev mailing list