def METHOD_NAME(tensor_shape, mask_creator, sparsity_val):
    tensor = tf_compat.Variable(tf_compat.random_normal(tensor_shape))
    sparsity = tf_compat.constant(sparsity_val)
    name = "{}_{}_{}_{}".format(
        mask_creator.__class__.__name__,
        "_".join([str(s) for s in tensor_shape]),
        str(sparsity_val),
        random.randint(0, 10000),
    )
    initial_mask = tf_compat.get_variable(
        name,
        tensor_shape,
        initializer=mask_creator.get_mask_initializer(tensor),
        dtype=tensor.dtype,
    )
    new_mask = mask_creator.create_sparsity_mask(tensor, sparsity)
    assert initial_mask.shape == tensor.shape
    assert new_mask.shape == tensor.shape
    with tf_compat.Session() as sess:
        sess.run(tf_compat.global_variables_initializer())
        eval_tensor_sparsity(initial_mask, sess)
        new_mask_sparsity = eval_tensor_sparsity(new_mask, sess)
        assert abs(new_mask_sparsity - sparsity_val) < 1e-2
        if isinstance(mask_creator, GroupedPruningMaskCreator):
            # Check that every value in the mask_creator grouping
            # is the same within the mask.  Assumes grouping applies
            # an absolte mean to each grouping
            for mask in [initial_mask, new_mask]:
                grouped_mask = mask_creator.group_tensor(mask)
                mask_vals_are_grouped = tf_compat.reduce_all(
                    tf_compat.logical_or(
                        tf_compat.equal(grouped_mask, 0.0),
                        tf_compat.equal(grouped_mask, 1.0),
                    )
                )
                assert sess.run(mask_vals_are_grouped)