code: def test_spark_ml_predict_invocation_with_target_variant(
      sagemaker_session,
  ):
      spark_ml_model_endpoint_name = unique_name_from_base(
          "integ-test-target-variant-sparkml"
      )
  
      model_data = sagemaker_session.upload_data(
          path=SPARK_ML_MODEL_LOCAL_PATH,
          key_prefix="integ-test-data/sparkml/model",
      )
  
      with tests.integ.timeout.timeout_and_delete_endpoint_by_name(
          spark_ml_model_endpoint_name, sagemaker_session
      ):
          spark_ml_model = SparkMLModel(
              model_data=model_data,
              role=ROLE,
              sagemaker_session=sagemaker_session,
              env={"SAGEMAKER_SPARKML_SCHEMA": SPARK_ML_MODEL_SCHEMA},
          )
  
          predictor = spark_ml_model.deploy(
              DEFAULT_INSTANCE_COUNT,
              DEFAULT_INSTANCE_TYPE,
              endpoint_name=spark_ml_model_endpoint_name,
          )
  
          # Validate that no exception is raised when the target_variant is specified.
          predictor.predict(
              SPARK_ML_TEST_DATA,
              target_variant=SPARK_ML_DEFAULT_VARIANT_NAME,
          )
  
          with pytest.raises(Exception) as exception_info:
              predictor.predict(
                  SPARK_ML_TEST_DATA,
                  target_variant=SPARK_ML_WRONG_VARIANT_NAME,
              )
  
          assert "ValidationError" in str(exception_info.value)
          assert SPARK_ML_WRONG_VARIANT_NAME in str(
              exception_info.value
          )
  
          # cleanup resources
          spark_ml_model.delete_model()
          sagemaker_session.sagemaker_client.delete_endpoint_config(
              EndpointConfigName=spark_ml_model_endpoint_name
          )
  
      # Validate resource cleanup
      with pytest.raises(Exception) as exception:
          sagemaker_session.sagemaker_client.describe_model(
              ModelName=spark_ml_model.name
          )
          assert "Could not find model" in str(exception.value)
          sagemaker_session.sagemaker_client.describe_endpoint_config(
              name=spark_ml_model_endpoint_name
          )
          assert "Could not find endpoint" in str(exception.value)
  
imports: from __future__ import absolute_import
  import json
  import math
  import os
  import pytest
  import scipy.stats
  from sagemaker import image_uris
  from sagemaker.deserializers import CSVDeserializer
  from sagemaker.s3 import S3Uploader
  from sagemaker.session import production_variant
  from sagemaker.sparkml import SparkMLModel
  from sagemaker.utils import unique_name_from_base
  from sagemaker.predictor import Predictor
  from sagemaker.serializers import CSVSerializer
  import tests.integ
label_desc: Use image node_id 5 for calling a global function with example usage: test_spark_ml_predict_invocation_with_target_variant(sagemaker_session) without return types