code: def test_fork(self):
      debug("calling pty.fork()")
      pid, master_fd = pty.fork()
      self.addCleanup(os.close, master_fd)
      if pid == pty.CHILD:
          # stdout should be connected to a tty.
          if not os.isatty(1):
              debug("Child's fd 1 is not a tty?!")
              os._exit(3)
  
          # After pty.fork(), the child should already be a session leader.
          # (on those systems that have that concept.)
          debug("In child, calling os.setsid()")
          try:
              os.setsid()
          except OSError:
              # Good, we already were session leader
              debug("Good: OSError was raised.")
              pass
          except AttributeError:
              # Have pty, but not setsid()?
              debug("No setsid() available?")
              pass
          except:
              # We don't want this error to propagate, escaping the call to
              # os._exit() and causing very peculiar behavior in the calling
              # regrtest.py !
              # Note: could add traceback printing here.
              debug("An unexpected error was raised.")
              os._exit(1)
          else:
              debug("os.setsid() succeeded! (bad!)")
              os._exit(2)
          os._exit(4)
      else:
          debug("Waiting for child (%d) to finish." % pid)
          # In verbose mode, we have to consume the debug output from the
          # child or the child will block, causing this test to hang in the
          # parent's waitpid() call.  The child blocks after a
          # platform-dependent amount of data is written to its fd.  On
          # Linux 2.6, it's 4000 bytes and the child won't block, but on OS
          # X even the small writes in the child above will block it.  Also
          # on Linux, the read() will raise an OSError (input/output error)
          # when it tries to read past the end of the buffer but the child's
          # already exited, so catch and discard those exceptions.  It's not
          # worth checking for EIO.
          while True:
              try:
                  data = os.read(master_fd, 80)
              except OSError:
                  break
              if not data:
                  break
              sys.stdout.write(
                  str(data.replace(b"\r\n", b"\n"), encoding="ascii")
              )
  
          ##line = os.read(master_fd, 80)
          ##lines = line.replace('\r\n', '\n').split('\n')
          ##if False and lines != ['In child, calling os.setsid()',
          ##             'Good: OSError was raised.', '']:
          ##    raise TestFailed("Unexpected output from child: %r" % line)
  
          (pid, status) = os.waitpid(pid, 0)
          res = os.waitstatus_to_exitcode(status)
          debug(
              "Child (%d) exited with code %d (status %d)."
              % (pid, res, status)
          )
          if res == 1:
              self.fail(
                  "Child raised an unexpected exception in os.setsid()"
              )
          elif res == 2:
              self.fail(
                  "pty.fork() failed to make child a session leader."
              )
          elif res == 3:
              self.fail(
                  "Child spawned by pty.fork() did not have a tty as stdout"
              )
          elif res != 4:
              self.fail("pty.fork() failed for unknown reasons.")
  
imports: from test.support import verbose, reap_children
  from test.support.import_helper import import_module
  import errno
  import os
  import pty
  import tty
  import sys
  import select
  import signal
  import socket
  import io
  import unittest
  import warnings
label_desc: Use image node_id 4 for calling the PtyTest obj's underlying member method code with example usage: obj.test_fork() without return types