def METHOD_NAME(container, path, contents):
    """Temporarily replace a file with the provided content in a container.
    Args:
        container (conu.DockerContainer): The container where the file is.
        path (str): The file path in the container.
        contents (str): The temporary content for the file.
    Yields:
        str: A path to a local file that will be synced back to the container.
    """
    with tempfile.TemporaryDirectory() as tempdir:
        backupfile = os.path.join(tempdir, "original")
        container.copy_from(path, backupfile)
        newfile = os.path.join(tempdir, "replacement")
        with open(newfile, "w") as f:
            f.write(contents)
        shutil.copymode(backupfile, newfile)
        container.copy_to(newfile, path)
        try:
            yield
        finally:
            container.copy_to(backupfile, path)