code: def harness(
      testdir_from_ns={None: os.curdir},
      argv=sys.argv,
      setup_func=None,
      default_tags=None,
  ):
      """Convenience mainline for a test harness "test.py" script.
  
          "testdir_from_ns" (optional) is basically a set of directories in
              which to look for test cases. It is a dict with:
                  <namespace>: <testdir>
              where <namespace> is a (short) string that becomes part of the
              included test names and an implicit tag for filtering those
              tests. By default the current dir is use with an empty namespace:
                  {None: os.curdir}
          "setup_func" (optional) is a callable that will be called once
              before any tests are run to prepare for the test suite. It
              is not called if no tests will be run.
          "default_tags" (optional)
  
      Typically, if you have a number of test_*.py modules you can create
      a test harness, "test.py", for them that looks like this:
  
          #!/usr/bin/env python
          if __name__ == "__main__":
              retval = testlib.harness()
              sys.exit(retval)
      """
      if not logging.root.handlers:
          logging.basicConfig()
      try:
          log_level, action, tags = _parse_opts(
              argv[1:], default_tags or []
          )
      except getopt.error:
          _, ex, _ = sys.exc_info()
          log.error(
              str(ex)
              + " (did you need a '--' before a '-TAG' argument?)"
          )
          return 1
      log.setLevel(log_level)
  
      if action == "help":
          print(__doc__)
          return 0
      if action == "list":
          return list_tests(testdir_from_ns, tags)
      elif action == "test":
          result = test(testdir_from_ns, tags, setup_func=setup_func)
          if result is None:
              return None
          return len(result.errors) + len(result.failures)
      else:
          raise TestError("unexpected action/mode: '%s'" % action)
  
imports: import os
  from os.path import join, basename, abspath, splitext, isfile, isdir, normpath, exists
  import sys
  import getopt
  import glob
  import time
  import unittest
  import importlib
  import logging
  import textwrap
  import traceback
label_desc: Use image node_id 12 for calling a global function with example usage: harness(testdir_from_ns, argv, setup_func, default_tags) and returns: int, list_tests, int, unknown, None