def test_log_metrics_column_order_sorted(tmp_path):
    """Test that the columns in the output metrics file are sorted by name."""
    logger = CSVLogger(tmp_path)
    logger.log_metrics({"c": 0.1})
    logger.log_metrics({"c": 0.2})
    logger.log_metrics({"b": 0.3})
    logger.log_metrics({"a": 0.4})
    logger.save()
    logger.log_metrics({"d": 0.5})
    logger.save()

    path_csv = os.path.join(logger.log_dir, _ExperimentWriter.NAME_METRICS_FILE)
    with open(path_csv) as fp:
        lines = fp.readlines()

    assert lines[0].strip() == "a,b,c,d,step"
Test that the columns in the output metrics file are sorted by name.
tests/tests_fabric/loggers/test_csv.py