'Creating a new class that inherits from decorated class is the more
common way I\'ve seen class decorators done - but it seems to cause
infinite recursion when super is called from inside methods in the
decorated class.'

def _patch_class(self, cls):

    orig_setUp = cls.setUp
    def unpatch_cleanup(cls_self):
        if cls_self._policies_patched:
            self.__exit__()
            cls_self._policies_patched = False
    def setUp(cls_self):
        if (not getattr(cls_self, '_policies_patched', False)):
            self.__enter__()
            cls_self._policies_patched = True
            cls_self.addCleanup(unpatch_cleanup, cls_self)
        orig_setUp(cls_self)
    cls.setUp = setUp
    return cls
