Author rbcollins
Recipients axitkhurana, barry, dablanc, ezio.melotti, michael.foord, r.david.murray, rbcollins, serhiy.storchaka, vajrasky
Date 2018-09-27.08:14:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1538036056.57.0.545547206417.issue24412@psf.upfronthosting.co.za>
In-reply-to
Content
Serhiy, thats not a design flaw, its a feature.

in a class hierarchy, setup and teardown ordering is undefined: implementors can choose whatever order they want to execute in. e.g.

class A(TestCase):
 def setUp(self):
  super().setUp()
  acquire1()

class B(A):
 def setUp(self):
  acquire2()
  super().setUp()

class C(B):
 def setUp(self):
  super().setUp()
  acquire3()

will acquire 2, then 1, then 3.

tearDown() is similarly ill defined.

Secondly, consider

class Example(TestCase):
 def setUp(self):
  self._1 = acquire()
  self.addCleanUp(acquire())
  self._3 = acquire()

 def tearDown(self):
  self._3.cleanUp()
  self._1.cleanUp()
  super().tearDown()

As such, there is no ordering of cleanup + teardown that is 'right' in all cases.

The question then becomes, which ordering *most facilitates* migration from tearDown to cleanup.

The allowable orders are:
 - with a more complex implementation, per-class (no)
 - before tearDown starts
 - after tearDown finishes

The common case tearDown tends to look like this:

def tearDown(self):
  <local cleanup>
  super().tearDown()

so, by placing doCleanup after tearDown, we make it possible for base classes in a test hierarchy to migrate to cleanups without breaking compatibility with child classes. The cost, as you note is that we make it harder for child classes to migrate until the base class has migrated.

But it is strictly better to permit the base class to migrate, because in projects you cannot be sure of all your subclasses out there in the wild, but you can be sure of all your base classes.
History
Date User Action Args
2018-09-27 08:14:16rbcollinssetrecipients: + rbcollins, barry, ezio.melotti, r.david.murray, michael.foord, axitkhurana, serhiy.storchaka, vajrasky, dablanc
2018-09-27 08:14:16rbcollinssetmessageid: <1538036056.57.0.545547206417.issue24412@psf.upfronthosting.co.za>
2018-09-27 08:14:16rbcollinslinkissue24412 messages
2018-09-27 08:14:16rbcollinscreate