def get_wrapped(func, wrapper_template, evaldict):
    # Preserve the argspec for the wrapped function so that testing
    # tools such as pytest can continue to use their fixture injection.
    args = getargspec(func)
    values = args.args[-len(args.defaults):] if args.defaults else None

    signature = formatargspec(*args)
    is_bound_method = hasattr(func, '__self__')
    if is_bound_method:
        args.args = args.args[1:]     # Omit 'self'
    callargs = formatargspec(*args, formatvalue=lambda v: '=' + v)

    ctx = {'signature': signature, 'funcargs': callargs}
    six.exec_(wrapper_template % ctx, evaldict)

    wrapper = evaldict['wrapper']

    update_wrapper(wrapper, func)
    if is_bound_method:
        wrapper = wrapper.__get__(func.__self__, type(func.__self__))
    return wrapper