code: def test_docstring(docstring):
      # We ignore differences in whitespace in the doctest output, and enable
      # the use of an ellipsis "..." to match any string in the doctest
      # output. An ellipsis is useful for, e.g., memory addresses or
      # imprecise floating point values.
      if docstring.name == "Handle":
          pytest.skip("Docstring is tested in RAFT.")
      optionflags = doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE
      runner = doctest.DocTestRunner(optionflags=optionflags)
  
      # These global names are pre-defined and can be used in doctests
      # without first importing them.
      globals = dict(cudf=cudf, np=np, cuml=cuml)
      docstring.globs = globals
  
      # Capture stdout and include failing outputs in the traceback.
      doctest_stdout = io.StringIO()
      with contextlib.redirect_stdout(doctest_stdout):
          runner.run(docstring)
          results = runner.summarize()
      try:
          assert not results.failed, (
              f"{results.failed} of {results.attempted} doctests failed for "
              f"{docstring.name}:\n{doctest_stdout.getvalue()}"
          )
      except AssertionError:
          # If some failed but all the failures were due to lack of multiGPU
          # support, we can skip. This code assumes that any MG-related failures
          # mean that all doctests failed for that reason, which is heavy-handed
          # and could miss a few things but is much easier than trying to
          # identify every line corresponding to any Exception raised.
          if (
              "cuML has not been built with multiGPU support"
              in doctest_stdout.getvalue()
          ):
              pytest.skip("Doctest requires MG support.")
          raise
  
file_path: cuml/python/cuml/tests/test_doctest.py
imports: from cuml.internals.safe_imports import gpu_only_import
  import pytest
  import contextlib
  import doctest
  import inspect
  import io
  import cuml
  from cuml.internals.safe_imports import cpu_only_import
label_desc: Use image node_id 4 for calling a global function with example usage: test_docstring(docstring) without return types