code: def test_training_details_autodiscovery_from_model_package_details(
      session, model_package_example, caplog
  ):
      session.sagemaker_client.search.side_effect = [
          SEARCH_TRAINING_JOB_EXAMPLE,
      ]
  
      training_details = (
          model_package_example.discover_training_details(
              sagemaker_session=session
          )
      )
      assert (
          training_details.training_job_details.training_arn
          == TRAINING_JOB_ARN
      )
      assert len(
          training_details.training_job_details.training_metrics
      ) == len(
          SEARCH_TRAINING_JOB_EXAMPLE["Results"][0]["TrainingJob"][
              "FinalMetricDataList"
          ]
      )
      assert len(
          training_details.training_job_details.hyper_parameters
      ) == len(
          SEARCH_TRAINING_JOB_EXAMPLE["Results"][0]["TrainingJob"][
              "HyperParameters"
          ]
      )
      assert (
          training_details.training_job_details.training_environment.container_image
          == [TRAINING_IMAGE]
      )
  
      model_package_example.inference_specification.containers = []
      model_package_example.discover_training_details(
          sagemaker_session=session
      )
      assert (
          "TrainingJobDetails auto-discovery failed. "
          "No associated training job. "
          "Please create one from scratch with TrainingJobDetails "
          "or use from_training_job_name() instead."
      ) in caplog.text
  
      model_package_example.inference_specification = None
      with caplog.at_level(logging.INFO):
          model_package_example.discover_training_details(
              sagemaker_session=session
          )
          assert (
              "TrainingJobDetails auto-discovery was unsuccessful. "
              "No inference specification found for the given model package."
              "Please create one from scratch with TrainingJobDetails "
              "or use from_training_job_name() instead."
          ) in caplog.text
  
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 31 for calling a global function with example usage: test_training_details_autodiscovery_from_model_package_details(session, model_package_example, caplog) without return types