diff --git a/gpMgmt/bin/gppylib/test/unit/gp_unittest.py b/gpMgmt/bin/gppylib/test/unit/gp_unittest.py index f0d174e9cee8b347b0f81b134e741d315d84675b..a9e82a522775714a221b5cc0cfa54ce5dbf77509 100644 --- a/gpMgmt/bin/gppylib/test/unit/gp_unittest.py +++ b/gpMgmt/bin/gppylib/test/unit/gp_unittest.py @@ -6,18 +6,36 @@ class GpTestCase(unittest.TestCase): super(GpTestCase, self).__init__(methodName) self.patches = [] self.mock_objs = [] + self.__class__.apply_patches_counter = 0 + self.__class__.tear_down_counter = 0 def apply_patches(self, patches): if self.patches: raise Exception('Test class is already patched!') self.patches = patches self.mock_objs = [p.start() for p in self.patches] + self.__class__.apply_patches_counter += 1 # if you have a tearDown() in your test class, - # be sure to call this using super.tearDown() + # be sure to call this using super(, self).tearDown() def tearDown(self): [p.stop() for p in self.patches] self.mock_objs = [] + self.__class__.tear_down_counter += 1 + + @classmethod + def setUpClass(cls): + cls.apply_patches_counter = 0 + cls.tear_down_counter = 0 + + @classmethod + def tearDownClass(cls): + if cls.apply_patches_counter > 0 and cls.apply_patches_counter != cls.tear_down_counter: + raise Exception("Unequal call for apply patches: %s, teardown: %s. " + "You probably need to add a super(, " + "self).tearDown() in your tearDown()" % (cls.apply_patches_counter, + cls.tear_down_counter)) + def add_setup(setup=None, teardown=None): """decorate test functions to add additional setup/teardown contexts""" diff --git a/gpMgmt/bin/gppylib/test/unit/test_unit_gpconfig.py b/gpMgmt/bin/gppylib/test/unit/test_unit_gpconfig.py index ea6e033c6e8bd92486760bf60c3ffd6198dc94f4..0739e86f8d5d59e3330fbf5691b847308308827d 100644 --- a/gpMgmt/bin/gppylib/test/unit/test_unit_gpconfig.py +++ b/gpMgmt/bin/gppylib/test/unit/test_unit_gpconfig.py @@ -68,6 +68,7 @@ class GpConfig(GpTestCase): def tearDown(self): shutil.rmtree(self.temp_dir) + super(GpConfig, self).tearDown() def createGpArrayWith2Primary2Mirrors(self): master = GpDB.initFromString( diff --git a/gpMgmt/bin/gppylib/test/unit/test_unit_gptransfer.py b/gpMgmt/bin/gppylib/test/unit/test_unit_gptransfer.py index f9442a6f910653aa22844b754b41dc07550c30ad..4237b32ae404af8bf164ae75024e005ff7ba75aa 100644 --- a/gpMgmt/bin/gppylib/test/unit/test_unit_gptransfer.py +++ b/gpMgmt/bin/gppylib/test/unit/test_unit_gptransfer.py @@ -153,6 +153,8 @@ class GpTransfer(GpTestCase): def tearDown(self): shutil.rmtree(self.TEMP_DIR) + super(GpTransfer, self).tearDown() + @patch('gptransfer.TableValidatorFactory', return_value=Mock()) def test__get_distributed_by_quotes_column_name(self, mock1): diff --git a/gpMgmt/bin/gppylib/test/unit/test_unit_repair.py b/gpMgmt/bin/gppylib/test/unit/test_unit_repair.py index f8e0439cc5cef05a572cb267ce1d61d082a987d2..94f1f7d74c3d7494718cc10e26d9c4134cb728c8 100644 --- a/gpMgmt/bin/gppylib/test/unit/test_unit_repair.py +++ b/gpMgmt/bin/gppylib/test/unit/test_unit_repair.py @@ -104,6 +104,7 @@ class RepairTestCase(GpTestCase): def tearDown(self): shutil.rmtree(self.repair_dir_path) + super(RepairTestCase, self).tearDown() if __name__ == '__main__': run_tests()