code: def test_variable_selection(estimator):
      transformer = clone(estimator)
  
      X, y = test_df(categorical=True, datetime=True)
  
      if transformer.__class__.__name__ == "TargetMeanRegressor":
          # y needs to be continuous
          y = X["var_10"]
          X.drop(["var_10"], axis=1, inplace=True)
  
      # cast one variable as category
      X[["cat_var2"]] = X[["cat_var2"]].astype("category")
  
      # cast datetime as object
      X[["date1"]] = X[["date1"]].astype("O")
  
      # Case 1: numerical variable as string
      transformer.set_params(variables="var_1")
      assert transformer.variables == "var_1"
  
      transformer.fit(X, y)
      assert transformer.variables == "var_1"
      assert transformer.variables_categorical_ == []
      assert transformer.variables_numerical_ == ["var_1"]
  
      # Case 2: numerical variable as list
      transformer.set_params(variables=["var_1"])
      assert transformer.variables == ["var_1"]
  
      transformer.fit(X, y)
      assert transformer.variables == ["var_1"]
      assert transformer.variables_categorical_ == []
      assert transformer.variables_numerical_ == ["var_1"]
  
      # Case 3: categorical variable as string
      transformer.set_params(variables="cat_var1")
      assert transformer.variables == "cat_var1"
  
      transformer.fit(X, y)
      assert transformer.variables == "cat_var1"
      assert transformer.variables_categorical_ == ["cat_var1"]
      assert transformer.variables_numerical_ == []
  
      # Case 4: categorical variable as list
      transformer.set_params(variables=["cat_var1"])
      assert transformer.variables == ["cat_var1"]
  
      transformer.fit(X, y)
      assert transformer.variables == ["cat_var1"]
      assert transformer.variables_categorical_ == ["cat_var1"]
      assert transformer.variables_numerical_ == []
  
      # Case 5: numerical and categorical variables
      transformer.set_params(
          variables=["var_1", "var_2", "cat_var1", "cat_var2", "date1"]
      )
      assert transformer.variables == [
          "var_1",
          "var_2",
          "cat_var1",
          "cat_var2",
          "date1",
      ]
  
      transformer.fit(X, y)
      assert transformer.variables == [
          "var_1",
          "var_2",
          "cat_var1",
          "cat_var2",
          "date1",
      ]
      assert transformer.variables_categorical_ == [
          "cat_var1",
          "cat_var2",
          "date1",
      ]
      assert transformer.variables_numerical_ == ["var_1", "var_2"]
  
      # Case 6: automatically select variables
      X_c = X[
          ["var_1", "var_2", "cat_var1", "cat_var2", "date1", "date2"]
      ].copy()
  
      transformer.set_params(variables=None)
      assert transformer.variables is None
  
      transformer.fit(X_c, y)
      assert transformer.variables is None
      assert transformer.variables_categorical_ == [
          "cat_var1",
          "cat_var2",
      ]
      assert transformer.variables_numerical_ == ["var_1", "var_2"]
  
      transformer.set_params(variables=["var_1", "cat_var1", "date2"])
      with pytest.raises(TypeError):
          transformer.fit(X, y)
  
      # Case 6: user passes empty list
      transformer.set_params(variables=[])
      with pytest.raises(ValueError):
          transformer.fit(X, y)
  
imports: import numpy
  import pandas
  import pytest
  from sklearn.base import clone
  from sklearn.exceptions import NotFittedError
  from sklearn.utils.estimator_checks import check_estimator
  from feature_engine._prediction.base_predictor import BaseTargetMeanEstimator
  from feature_engine._prediction.target_mean_classifier import TargetMeanClassifier
  from feature_engine._prediction.target_mean_regressor import TargetMeanRegressor
  from feature_engine.discretisation import EqualFrequencyDiscretiser, EqualWidthDiscretiser
  from feature_engine.encoding import MeanEncoder
  from tests.estimator_checks.dataframe_for_checks import test_df
  from tests.estimator_checks.fit_functionality_checks import check_error_if_y_not_passed
label_desc: Use image node_id 6 for calling a global function with example usage: test_variable_selection(estimator) without return types