def wrap(func): project = test_plugin_manager.project_name HookImplementationMarker(project)( tryfirst=tryfirst, trylast=trylast, hookwrapper=hookwrapper, specname=specname, )(func) _specname = specname or func.__name__ hook_caller = getattr(test_plugin_manager.hook, _specname, None) assert hook_caller, f"No hook with with name: {_specname}" opts = getattr(func, HookImplementation.format_tag(project)) hook_caller._add_hookimpl(HookImplementation(func, **opts)) return func
def wrap(func, specname=None, *, tryfirst=True, trylast=None): project = test_plugin_manager.project_name marker = HookImplementationMarker(project) marker(tryfirst=tryfirst, trylast=trylast, specname=specname)(func) _specname = specname or func.__name__ hook_caller = getattr(test_plugin_manager.hook, _specname, None) assert hook_caller, f"No hook with with name: {_specname}" opts = getattr(func, HookImplementation.format_tag(project)) impl = HookImplementation(func, **opts) hook_caller._add_hookimpl(impl) try: yield hook_caller finally: if impl in hook_caller._nonwrappers: hook_caller._nonwrappers.remove(impl) if impl in hook_caller._wrappers: hook_caller._wrappers.remove(impl) assert impl not in hook_caller.get_hookimpls()