code: def test_model_package_autodiscovery(
      session, model_overview_example, training_details_example
  ):
      session.sagemaker_client.describe_model_package.side_effect = [
          DESCRIBE_MODEL_PACKAGE_EXAMPLE,
          DESCRIBE_MODEL_PACKAGE_EXAMPLE,
          MISSING_MODEL_PACKAGE_CLIENT_ERROR,
          DESCRIBE_MODEL_PACKAGE_EXAMPLE,
          DESCRIBE_MODEL_PACKAGE_EXAMPLE,
      ]
  
      session.sagemaker_client.search.side_effect = [
          SEARCH_MODEL_CARD_WITH_MODEL_ID_EMPTY_EXAMPLE,
          SEARCH_MODEL_CARD_WITH_MODEL_ID_EXAMPLE,
          SEARCH_IAM_PERMISSION_CLIENT_ERROR,
          SEARCH_MODEL_CARD_WITH_MODEL_ID_EMPTY_EXAMPLE,
      ]
  
      model_package_details = ModelPackage.from_model_package_arn(
          MODEL_PACKAGE_ARN, sagemaker_session=session
      )
      assert (
          model_package_details.model_package_arn == MODEL_PACKAGE_ARN
      )
      assert (
          model_package_details.model_package_group_name
          == MODEL_PACKAGE_GROUP_NAME
      )
      assert (
          model_package_details.inference_specification.containers[
              0
          ].model_data_url
          == MODEL_DATA_URL
      )
      assert (
          model_package_details.created_by.user_profile_name
          == USER_PROFILE_NAME
      )
  
      with pytest.raises(
          ValueError,
          match=re.escape(
              f"The model package has already been associated with {[MODEL_CARD_NAME]} model cards."
          ),
      ):
          ModelPackage.from_model_package_arn(
              MODEL_PACKAGE_ARN, sagemaker_session=session
          )
  
      with pytest.raises(
          ValueError,
          match=re.escape(
              f"Model package details for {MODEL_PACKAGE_ARN} could not be found. Make sure the model package name or ARN is valid."  # noqa E501  # pylint: disable=c0301
          ),
      ):
          ModelPackage.from_model_package_arn(
              MODEL_PACKAGE_ARN, sagemaker_session=session
          )
  
      with pytest.raises(
          ValueError,
          match=re.escape(
              "Received AccessDeniedException while calling SageMaker Search operation "
              "on resource ModelCard. This could mean the IAM role does not "
              "have the resource permissions, in which case please add resource access "
              "and retry. For cases where the role has tag based resource policy, "
              "continuing to wait for tag propagation.."
          ),
      ):
          ModelPackage.from_model_package_arn(
              MODEL_PACKAGE_ARN, sagemaker_session=session
          )
  
imports: from __future__ import absolute_import
  import io
  import os
  import json
  import datetime
  import re
  import logging
  import pytest
  from mock import patch, Mock
  from botocore.exceptions import ClientError
  import botocore.response
  from sagemaker.model_card import schema_constraints
  from sagemaker.model_card import Environment, ModelOverview, IntendedUses, BusinessDetails, ObjectiveFunction, TrainingMetric, HyperParameter, Metric, TrainingDetails, MetricGroup, EvaluationJob, AdditionalInformation, ModelCard, Function, TrainingJobDetails, ModelPackage
  from sagemaker.model_card.model_card import ModelCardExportJob, ModelPackageCreator, SourceAlgorithm, Container, InferenceSpecification
  from sagemaker.model_card.helpers import _MaxSizeArray, _IsList, _OneOf, _IsModelCardObject, _JSONEncoder, _hash_content_str, _DefaultToRequestDict, _SkipEncodingDecoding
  from sagemaker.model_card.evaluation_metric_parsers import EvaluationMetricTypeEnum, EVALUATION_METRIC_PARSERS
label_desc: Use image node_id 29 for calling a global function with example usage: test_model_package_autodiscovery(session, model_overview_example, training_details_example) without return types