code: def test_device_stats_monitor_warning_when_psutil_not_available(
      monkeypatch, tmp_path
  ):
      """Test that warning is raised when psutil is not available."""
      import lightning.pytorch.callbacks.device_stats_monitor as imports
  
      monkeypatch.setattr(imports, "_PSUTIL_AVAILABLE", False)
      monitor = DeviceStatsMonitor()
      trainer = Trainer(logger=CSVLogger(tmp_path))
      assert trainer.strategy.root_device == torch.device("cpu")
      with pytest.raises(
          ModuleNotFoundError, match="psutil` is not installed"
      ):
          monitor.setup(trainer, Mock(), "fit")
  
imports: import csv
  import os
  import re
  from typing import Dict, Optional
  from unittest import mock
  from unittest.mock import Mock
  import pytest
  import torch
  from lightning.pytorch import Trainer
  from lightning.pytorch.accelerators.cpu import _CPU_PERCENT, _CPU_SWAP_PERCENT, _CPU_VM_PERCENT, get_cpu_stats
  from lightning.pytorch.callbacks import DeviceStatsMonitor
  from lightning.pytorch.callbacks.device_stats_monitor import _prefix_metric_keys
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.loggers import CSVLogger
  from lightning.pytorch.utilities.exceptions import MisconfigurationException
  from lightning.pytorch.utilities.rank_zero import rank_zero_only
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 6 for calling a global function with example usage: test_device_stats_monitor_warning_when_psutil_not_available(monkeypatch, tmp_path) without return types