Add text support for custom test descriptions

validmind-library
2.8.20
documentation
enhancement
highlight
Published

April 16, 2025

We have enhanced the custom test framework, allowing you to define custom descriptions for your tests. If a test returns a string, it will be used as the test description, overriding the automatic description generation.

@vm.test("my_custom_tests.MyCustomTest")
def my_custom_test(dataset, model):
    """
    This is a custom test that does nothing.
    """
    y_true = dataset.y
    y_pred = dataset.y_pred(model)

    confusion_matrix = metrics.confusion_matrix(y_true, y_pred)

    cm_display = metrics.ConfusionMatrixDisplay(
        confusion_matrix=confusion_matrix, display_labels=[False, True]
    )
    cm_display.plot()

    plt.close()  # close the plot to avoid displaying it

    return cm_display.figure_, "Test Description - Confusion Matrix", pd.DataFrame({"Value": [1, 2, 3]})

Run test

from validmind.tests import run_test

result = run_test(
    "my_custom_tests.MyCustomTest",
    inputs={"model": "model", "dataset": "test_dataset"},
)

Output

A web page titled My Custom Test displays a confusion matrix under the section labeled Test Description - Confusion Matrix. The page is divided into two main sections: Tables and Figures. The Tables section lists values 1, 2, and 3 in a vertical column. The Figures section contains a heatmap confusion matrix with a color gradient from yellow to dark purple, representing values from 0 to 1200. The matrix has axes labeled True label and Predicted label, with categories False and True on both axes.

Confusion matrix visualization