class_docstr: Runs test snippets in the documentation.
code: def test_doc(self, docname: str, doctree: Node) -> None:
      groups: dict[str, TestGroup] = {}
      add_to_all_groups = []
      self.setup_runner = SphinxDocTestRunner(
          verbose=False, optionflags=self.opt
      )
      self.test_runner = SphinxDocTestRunner(
          verbose=False, optionflags=self.opt
      )
      self.cleanup_runner = SphinxDocTestRunner(
          verbose=False, optionflags=self.opt
      )
  
      self.test_runner._fakeout = self.setup_runner._fakeout  # type: ignore[attr-defined]
      self.cleanup_runner._fakeout = self.setup_runner._fakeout  # type: ignore[attr-defined]
  
      if self.config.doctest_test_doctest_blocks:
  
          def condition(node: Node) -> bool:
              return (
                  isinstance(node, (nodes.literal_block, nodes.comment))
                  and "testnodetype" in node
              ) or isinstance(node, nodes.doctest_block)
  
      else:
  
          def condition(node: Node) -> bool:
              return (
                  isinstance(node, (nodes.literal_block, nodes.comment))
                  and "testnodetype" in node
              )
  
      for node in doctree.findall(condition):  # type: Element
          if self.skipped(node):
              continue
  
          source = node["test"] if "test" in node else node.astext()
          filename = self.get_filename_for_node(node, docname)
          line_number = self.get_line_number(node)
          if not source:
              logger.warning(
                  __("no code/output in %s block at %s:%s"),
                  node.get("testnodetype", "doctest"),
                  filename,
                  line_number,
              )
          code = TestCode(
              source,
              type=node.get("testnodetype", "doctest"),
              filename=filename,
              lineno=line_number,
              options=node.get("options"),
          )
          node_groups = node.get("groups", ["default"])
          if "*" in node_groups:
              add_to_all_groups.append(code)
              continue
          for groupname in node_groups:
              if groupname not in groups:
                  groups[groupname] = TestGroup(groupname)
              groups[groupname].add_code(code)
      for code in add_to_all_groups:
          for group in groups.values():
              group.add_code(code)
      if self.config.doctest_global_setup:
          code = TestCode(
              self.config.doctest_global_setup,
              "testsetup",
              filename="<global_setup>",
              lineno=0,
          )
          for group in groups.values():
              group.add_code(code, prepend=True)
      if self.config.doctest_global_cleanup:
          code = TestCode(
              self.config.doctest_global_cleanup,
              "testcleanup",
              filename="<global_cleanup>",
              lineno=0,
          )
          for group in groups.values():
              group.add_code(code)
      if not groups:
          return
  
      show_successes = self.config.doctest_show_successes
      if show_successes:
          self._out(
              "\n"
              f"Document: {docname}\n"
              f'----------{"-" * len(docname)}\n'
          )
      for group in groups.values():
          self.test_group(group)
      # Separately count results from setup code
      res_f, res_t = self.setup_runner.summarize(
          self._out, verbose=False
      )
      self.setup_failures += res_f
      self.setup_tries += res_t
      if self.test_runner.tries:
          res_f, res_t = self.test_runner.summarize(
              self._out, verbose=show_successes
          )
          self.total_failures += res_f
          self.total_tries += res_t
      if self.cleanup_runner.tries:
          res_f, res_t = self.cleanup_runner.summarize(
              self._out, verbose=show_successes
          )
          self.cleanup_failures += res_f
          self.cleanup_tries += res_t
  
imports: from __future__ import annotations
  import doctest
  import re
  import sys
  import time
  from io import StringIO
  from os import path
  from typing import TYPE_CHECKING, Any, Callable
  from docutils import nodes
  from docutils.parsers.rst import directives
  from packaging.specifiers import InvalidSpecifier, SpecifierSet
  from packaging.version import Version
  import sphinx
  from sphinx.builders import Builder
  from sphinx.locale import __
  from sphinx.util import logging
  from sphinx.util.console import bold
  from sphinx.util.docutils import SphinxDirective
  from sphinx.util.osutil import relpath
label_desc: Use image node_id 11 for calling the DocTestBuilder obj's underlying member method code with example usage: obj.test_doc(docname, doctree) and returns: unknown, unknown