def with_patched_object(obj, attr_name, patched_value):
    """Decorator that patches an object before the decorated method
    is called and restores it afterwards.

    This is a wrapper around :func:`fudge.patcher.patch_object`

    Example::

        >>> from fudge import with_patched_object
        >>> class Session:
        ...     state = 'clean'
        ...
        >>> @with_patched_object(Session, "state", "dirty")
        ... def test():
        ...     print Session.state
        ...
        >>> test()
        dirty
        >>> print Session.state
        clean

    """
    def patcher(method):
        @wraps(method)
        def method_call(*m_args, **m_kw):
            patched_obj = patch_object(obj, attr_name, patched_value)
            try:
                return method(*m_args, **m_kw)
            finally:
                patched_obj.restore()
        return method_call
    return patcher