def case_uses_module(module, verbose = None):
    def wrapped_func(klass):
        if verbose == None:
            vvv = ALL_VERBOSE or CLASS_VERBOSE
        else:
            vvv = verbose

        if not hasattr(klass, '_module_disposer'):
            klass._module_disposer = {}
        klass._module_disposer[module.__name__] = _ResourceMonitor()

        realSetUp = klass.setUp
        def wrappedSetUp(self):
            if vvv:
                print("setUp @ %s: retrieving current resources" % klass.__name__)
            klass._module_disposer[module.__name__].before_last_setup = module._resource_manager.get_current_resources()
            if vvv:
                print("setUp @ %s: retrieved resources: %s" % (klass.__name__, klass._module_disposer[module.__name__].before_last_setup))

            realSetUp(self)
        klass.setUp = wrappedSetUp

        realTearDown = klass.tearDown
        def wrappedTearDown(self):
            realTearDown(self)

            if vvv:
                print("tearDown @ %s: Remaining resources: %s" % (klass.__name__, module._resource_manager.get_current_resources()))

            resources = klass._module_disposer[module.__name__].before_last_setup
            module._resource_manager.remove_resources_from(resources)
            if vvv:
                print("tearDown @ %s: resources cleaned. Remaining: %s" % (klass.__name__, module._resource_manager.get_current_resources()))
        klass.tearDown = wrappedTearDown

        return klass
    return wrapped_func
dataset/ETHPy150Open weblabdeusto/weblabdeusto/server/src/test/util/module_disposer.py/case_uses_module/original