code: def add_code(self, code: TestCode, prepend: bool = False) -> None:
      if code.type == "testsetup":
          if prepend:
              self.setup.insert(0, code)
          else:
              self.setup.append(code)
      elif code.type == "testcleanup":
          self.cleanup.append(code)
      elif code.type == "doctest":
          self.tests.append([code])
      elif code.type == "testcode":
          # "testoutput" may replace the second element
          self.tests.append((code, None))
      elif code.type == "testoutput":
          if self.tests:
              latest_test = self.tests[-1]
              if len(latest_test) == 2:
                  self.tests[-1] = [latest_test[0], code]
      else:
          raise RuntimeError(__("invalid TestCode type"))
  
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 2 for calling the TestGroup obj's underlying member method code with example usage: obj.add_code(code, prepend) without return types