Questions after testtools merge

Jonathan Lange jml at canonical.com
Thu Jan 7 03:43:51 GMT 2010


On Wed, Jan 6, 2010 at 5:09 PM, Robert Collins
<robertc at robertcollins.net> wrote:
> 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 had a chat about this w/ Rob earlier today. He has won me over to
his way of thinking.

jml



More information about the bazaar mailing list