code: def test_X_data_only_loaded_when_required(
      make_ensemble_builder: Callable[..., EnsembleBuilder],
      make_run: Callable[..., Run],
      metric: Scorer,
      should_be_loaded: bool,
  ) -> None:
      """
      Expects
      -------
      * Should only load X_train if it's required
      * TODO should only load X_test if it's required
      """
      metrics = [metric]
      builder = make_ensemble_builder(metrics=metrics)
  
      # Make a dummy which is required for the whole pipeline to run
      make_run(
          dummy=True,
          losses={metric.name: 1000},
          backend=builder.backend,
      )
  
      # Make a run that has no losses recorded, forcing us to use the metric
      make_run(
          dummy=False,
          predictions={"ensemble": builder.targets("ensemble")},
          losses=None,
          backend=builder.backend,
      )
  
      ret_value = builder.X_data()
      builder.X_data = Mock(return_value=ret_value)
  
      builder.main()
  
      assert builder.X_data.called == should_be_loaded
  
imports: from __future__ import annotations
  from typing import Callable
  import random
  import time
  from pathlib import Path
  import numpy
  from autosklearn.automl_common.common.utils.backend import Backend
  from autosklearn.ensemble_building import EnsembleBuilder, Run
  from autosklearn.metrics import Scorer, accuracy, make_scorer
  from autosklearn.util.functional import bound, pairs
  import pytest
  from pytest_cases import fixture, parametrize
  from unittest.mock import Mock, patch
  from test.conftest import DEFAULT_SEED
  from test.fixtures.metrics import acc_with_X_data
label_desc: Use image node_id 31 for calling a global function with example usage: test_X_data_only_loaded_when_required(make_ensemble_builder, make_run, metric, should_be_loaded) without return types