code: def test_set_num_threads_if_needed(
      _, set_num_threads_mock, num_processes, expected
  ):
      assert "OMP_NUM_THREADS" not in os.environ
      _set_num_threads_if_needed(num_processes)
      set_num_threads_mock.assert_called_with(expected)
      assert os.environ["OMP_NUM_THREADS"] == str(expected)
  
      # if env variable is already set, no change
      set_num_threads_mock.reset_mock()
      _set_num_threads_if_needed(1)
      set_num_threads_mock.assert_not_called()
      assert os.environ["OMP_NUM_THREADS"] == str(expected)
  
imports: import functools
  import os
  from functools import partial
  from pathlib import Path
  from unittest import mock
  import pytest
  import torch
  from lightning.fabric.accelerators import CPUAccelerator, CUDAAccelerator, MPSAccelerator
  from lightning.fabric.plugins.environments import LightningEnvironment
  from lightning.fabric.strategies import DDPStrategy, SingleDeviceStrategy
  from lightning.fabric.strategies.launchers.multiprocessing import _MultiProcessingLauncher
  from lightning.fabric.utilities.distributed import _gather_all_tensors, _set_num_threads_if_needed, _suggested_max_num_threads, _sync_ddp, is_shared_filesystem
  from tests_fabric.helpers.runif import RunIf
label_desc: Use image node_id 10 for calling a global function with example usage: test_set_num_threads_if_needed(_, set_num_threads_mock, num_processes, expected) without return types