Questions after testtools merge

Robert Collins robertc at robertcollins.net
Wed Jan 6 06:09:23 GMT 2010


On Wed, 2010-01-06 at 15:44 +1100, Jonathan Lange wrote:

> > This saved me from defining a specific class with its associated
> > setUp/tearDown for one test.
> >
> 
> Yes, I think that cleanups before tearDown are to be preferred.

This problem is symmetric - there isn't a right way inferrable from just
the fact that teardown and cleanups mix badly...

Here is an unsafe case, with cleanups before teardown:

base:
 def setUp:
    self.something = mkstemp()
    self.addCleanup(rm -rf something)

child:
 def setUp:
    self.db = newDB(self.something)
 def tearDown:
    self.db.tearDown()

Which ever way you put cleanups, they interact badly when you mix a
single resource of the test with cleanups & teardowns. And that is a
migration issue.

If you put cleanups before teardown, you cannot migrate the base without
affecting children.

If you put cleanups after teardown, you can migrate the baseclass
without affecting children - children just need to wait for the base
class to switch to cleanups before migrating themself. I argue that this
is safer, because a child knows its base classes, but a base class
doesn't know its children: so the tie break should be in favour of the
base class so that decisions made in ignorance of a child class are more
likely to be safe.

>  I've
> written addCleanup for testtools, Trial and for Launchpad, and for
> each of them I put the cleanup before tearDown.
> 
> I think the Python decision is a mistake, and that the write place to
> correct it is in Python. I encourage you to advocate the change,
> perhaps with a patch, on the python-dev mailing list, or the
> testing-in-python mailing list.

I'll argue this there too, if needed :).

-Rob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20100106/fb37bd49/attachment.pgp 


More information about the bazaar mailing list