def setUp(self):
    """Only instantiate the matcher once"""
if self.matcher is None:
    self.__class__.matcher = Matcher()
self.__class__.num_of_tests = len(list(filter(self.isTestMethod, dir(self))))
self.__class__.counter = self.counter + 1

def tearDown(self):
    """And kill it when done"""
if self.counter == self.num_of_tests:
    print('KILL KILL KILL')
del self.__class__.matcher
Модульный тест Python с дорогой настройкой