[Tutor] Please help understanding unittest fixtures
Peter Otten
__peter__ at web.de
Mon Aug 22 10:35:10 CEST 2011
Steven D'Aprano wrote:
> D. Guandalino wrote:
>> In this case is there a
>> way to force just one setUp() call?
>
>
> I don't know if this is the best way, but the first way that comes to
> mind is this:
>
>
> class C(TestCase):
> initialised = False
> def setUp(self):
> if self.initialised:
> return
> # Make sure you save the flag on the class, not the instance!
> self.__class__.initialised = True
> ...
Python 2.7 and 3.2 support setUpClass()/tearDownClass() classmethods, see
http://docs.python.org/library/unittest.html#unittest.TestCase.setUpClass
More information about the Tutor
mailing list