code: def mock_tty(monkeypatch):
      class WriteThread(threading.Thread):
          def __init__(self, fname):
              threading.Thread.__init__(self)
              self._fname = fname
              self._q = queue.Queue()
  
          def run(self):
              with open(self._fname, "w") as fp:
                  while True:
                      data = self._q.get()
                      if data == "_DONE_":
                          break
                      fp.write(data)
                      fp.flush()
  
          def add(self, input_str):
              self._q.put(input_str)
  
          def stop(self):
              self.add("_DONE_")
  
      with tempfile.TemporaryDirectory() as tmpdir:
          fds = dict()
  
          def setup_fn(input_str):
              fname = os.path.join(tmpdir, "file.txt")
              if platform.system() != "Windows":
                  os.mkfifo(fname, 0o600)
                  writer = WriteThread(fname)
                  writer.start()
                  writer.add(input_str)
                  fds["writer"] = writer
                  monkeypatch.setattr(
                      "termios.tcflush", lambda x, y: None
                  )
              else:
                  # windows doesn't support named pipes, just write it
                  # TODO: emulate msvcrt to support input on windows
                  with open(fname, "w") as fp:
                      fp.write(input_str)
              fds["stdin"] = open(fname)
              monkeypatch.setattr("sys.stdin", fds["stdin"])
              sys.stdin.isatty = lambda: True
              sys.stdout.isatty = lambda: True
  
          yield setup_fn
  
          writer = fds.get("writer")
          if writer:
              writer.stop()
              writer.join()
          stdin = fds.get("stdin")
          if stdin:
              stdin.close()
  
      del sys.stdin.isatty
      del sys.stdout.isatty
  
imports: import os
  import platform
  import queue
  import sys
  import tempfile
  import threading
  import time
  from unittest import mock
  import pytest
  import wandb
label_desc: Use image node_id 1 for calling a global function with example usage: mock_tty(monkeypatch) without return types