class_docstr: Simple plugin to defer pytest-xdist hook functions.
code: def _rotate_cuda_visible_devices(self, worker_id):
      if worker_id == "master":
          # `worker_id` can be `master` if `pytest-xdist` is installed and
          # run without `-n` option.
          return
  
      n_gpu = os.environ.get("CUPY_TEST_GPU_LIMIT")
      if n_gpu is None:
          print(
              "Tip: when using pytest-xdist, you can automatically rotate"
              " CUDA_VISIBLE_DEVICES for each test worker by setting"
              " CUPY_TEST_GPU_LIMIT environment variable."
          )
          return
      n_gpu = int(n_gpu)
  
      assert worker_id.startswith("gw")
      w = int(worker_id[2:])
  
      devices = os.environ.get("CUDA_VISIBLE_DEVICES")
      if devices is None:
          devices = [str(k) for k in range(n_gpu)]
      else:
          devices = devices.split(",")[:n_gpu]
      devices = collections.deque(devices)
      devices.rotate(w)
      devices = ",".join(devices)
      os.environ["CUDA_VISIBLE_DEVICES"] = devices
      # With PyTest's default, the print will be shown as
      # "--- Captured stdout setup ---" on failure.
      print(f"CUDA_VISIBLE_DEVICES={devices}")
  
file_path: cupy/tests/conftest.py
imports: import collections
  import os
  import subprocess
  import sys
  import pytest
label_desc: Use image node_id 1 for calling the DeferPlugin obj's underlying member method code with example usage: obj._rotate_cuda_visible_devices(worker_id) without return types