def test_replace_nonreplaceable_vars_force():
    """
    The conversion should not error out if the replace_uses_of_vars_after_op is executed with
    force_replace=True Also we test that, the new nonreplaceable_vars_upstream is propagated
    after the code exist `with block`.
    """
    constexpr_op = "constexpr_sparse_to_dense"
    @mb.program(input_specs=[mb.TensorSpec(shape=(4, 2))])
    def prog(x):
        constexpr = CONSTEXPR_FUNCS[constexpr_op]((4, 2))
        return mb.add(x=x, y=constexpr)

    block = prog.functions["main"]
    constexpr_op = block.find_ops(op_type=constexpr_op)[0]
    add_op = block.find_ops(op_type="add")[0]

    assert len(add_op.outputs[0].nonreplaceable_vars_upstream) == 1

    with block:
        const = mb.const(val=np.random.rand(4, 2), before_op=constexpr_op)
        block.replace_uses_of_var_after_op(
            anchor_op=constexpr_op,
            old_var=constexpr_op.outputs[0],
            new_var=const,
            force_replace=True,
        )
        block.remove_ops([constexpr_op])

    assert len(add_op.outputs[0].nonreplaceable_vars_upstream) == 0

    The conversion should not error out if the replace_uses_of_vars_after_op is executed with
    force_replace=True Also we test that, the new nonreplaceable_vars_upstream is propagated
    after the code exist `with block`.
    
coremltools/converters/mil/mil/tests/test_block.py