code: def test_try_import_each_module():
      mock_sys_modules = sys.modules.copy()
      modules_to_import = ["json", "logging", "re"]
      fake_module = "fake_import_does_not_exist"
  
      for lib in modules_to_import:
          if lib in mock_sys_modules:
              del mock_sys_modules[lib]
  
      with patch(
          "ray._private.utils.logger.exception"
      ) as mocked_log_exception:
          with patch.dict(sys.modules, mock_sys_modules):
              patched_sys_modules = sys.modules
  
              try_import_each_module(
                  modules_to_import[:1]
                  + [fake_module]
                  + modules_to_import[1:]
              )
  
              # Verify modules are imported.
              for lib in modules_to_import:
                  assert (
                      lib in patched_sys_modules
                  ), f"lib {lib} not in {patched_sys_modules}"
  
              # Verify import error is printed.
              found = False
              for args, _ in mocked_log_exception.call_args_list:
                  found = any(fake_module in arg for arg in args)
                  if found:
                      break
  
              assert found, (
                  "Did not find print call with import "
                  f"error {mocked_log_exception.call_args_list}"
              )
  
file_path: ray/python/ray/tests/test_utils.py
imports: import pytest
  import logging
  from ray._private.utils import get_or_create_event_loop, pasre_pg_formatted_resources_to_original, try_import_each_module, get_current_node_cpu_model_name
  from unittest.mock import patch, mock_open
  import sys
label_desc: Use image node_id 3 for calling a global function with example usage: test_try_import_each_module() without return types