code: def test_gpu_info_mock(mock_pynvml_module, mock_gpu_is_available):
      global query_resp
  
      query_resp = {
          "gpu": [
              {
                  "fb_memory_usage": {"used": 100.0, "total": 11000.0},
                  "utilization": {"gpu_util": 50.0},
              }
          ]
      }
  
      assert torch.cuda.is_available()
      _test_gpu_info()
  
      # Tests https://github.com/pytorch/ignite/issues/1040
      query_resp = {
          "gpu": [
              {
                  "fb_memory_usage": {"used": 100.0, "total": 11000.0},
                  "utilization": {"gpu_util": "N/A"},
              }
          ]
      }
      _test_gpu_info()
  
      def _test_with_custom_query(resp, warn_msg, check_compute=False):
          from pynvml.smi import nvidia_smi
  
          def query(*args, **kwargs):
              return resp
  
          def getInstance():
              nvsmi = Mock()
              nvsmi.DeviceQuery = Mock(side_effect=query)
              return nvsmi
  
          nvidia_smi.getInstance = Mock(side_effect=getInstance)
          gpu_info = GpuInfo()
          if check_compute:
              with pytest.warns(UserWarning, match=warn_msg):
                  gpu_info.compute()
  
          # with Engine
          engine = Engine(lambda engine, batch: 0.0)
          engine.state = State(metrics={})
  
          with pytest.warns(UserWarning, match=warn_msg):
              gpu_info.completed(engine, name="gpu info")
  
      # No GPU info
      _test_with_custom_query(
          resp={},
          warn_msg=r"No GPU information available",
          check_compute=True,
      )
  
      # No GPU memory info
      _test_with_custom_query(
          resp={"gpu": [{"utilization": {}}]},
          warn_msg=r"No GPU memory usage information available",
      )
  
      # No GPU utilization info
      _test_with_custom_query(
          resp={"gpu": [{"fb_memory_usage": {}}]},
          warn_msg=r"No GPU utilization information available",
      )
  
file_path: ignite/tests/ignite/contrib/metrics/test_gpu_info.py
imports: from unittest.mock import Mock, patch
  import pytest
  import torch
  from ignite.contrib.metrics import GpuInfo
  from ignite.engine import Engine, State
label_desc: Use image node_id 7 for calling a global function with example usage: test_gpu_info_mock(mock_pynvml_module, mock_gpu_is_available) and returns: resp, nvsmi