def replacing_yield(o, attr, val):
    """Context manager to temporarily replace an attribute"""
    old = getattr(o, attr)
    try:
        yield setattr(o, attr, val)
    finally:
        setattr(o, attr, old)
