def _patch_class(self, module, name, autospec=True, attach_as=None):
        if autospec:
            instance_mock = mock.MagicMock(spec=getattr(module, name))
        else:
            instance_mock = mock.MagicMock()

        patcher = mock.patch.object(module, name, autospec=autospec)
        class_mock = patcher.start()
        self.addCleanup(patcher.stop)
        class_mock.return_value = instance_mock

        if attach_as is None:
            attach_class_as = name
            attach_instance_as = name.lower()
        else:
            attach_class_as = attach_as + '_class'
            attach_instance_as = attach_as

        self.master_mock.attach_mock(class_mock, attach_class_as)
        self.master_mock.attach_mock(instance_mock, attach_instance_as)

        return class_mock, instance_mock
Patch class, create class instance mock and attach them to
dataset/ETHPy150Open openstack/anvil/anvil/test.py/MockTestCase._patch_class