[TIP] addCleanup for setUpClass()?
Prasanna Santhanam
tsp at apache.org
Thu Aug 1 03:28:30 PDT 2013
On Thu, Aug 01, 2013 at 02:53:51PM +0530, Prasanna Santhanam wrote:
> In unittest with the fix for [1] unittest.addCleanups can perform
> cleanup for objects in the LIFO structure if setUp fails midway during
> an expensive test. Is there something similar for setUpClass() as well
> that was introduced with unittest2?
>
> If not - would something like the following work?
>
> MyTestClass(TestCase):
> @classmethod
> def setUpClass(cls)
> try:
> setUpClass()
> except:
> cls.tearDownClass()
Specifically I attempted this:
class MyTestClass(unittest.case.TestCase):
@classmethod
def setUpClass(cls):
try:
super(MyTestClass, cls).setUpClass()
except Exception:
super(MyTestClass, cls).tearDownClass()
But I see it has no effect at all on the tests implemented using MyTestClass.
My last resort would be to include the try..except block into every test :/
--
Prasanna.,
------------------------
Powered by BigRock.com
More information about the testing-in-python
mailing list