def pop_node(node):
    """Remove and return a node but leave its tail text behind."""
    parent, prev = node.getparent(), node.getprevious()
    tail = node.tail or ''

    if prev is None:
        if parent.text is None:
            parent.text = ''
        parent.text += tail
    else:
        prev.tail += tail

    parent.remove(node)
    return node