title: python pytest occasionally fails with OSError: reading from stdin while output is captured
body: <p>While running a particular <code>unittest</code> with <code>pytest</code>, it occasionally fails with this error (mentioned in the title) and from the stack trace it happens on the line</p>
  
  <p><code>choice = input().lower()</code></p>
  
  <p>when the control reaches this statement, the entire function is:</p>
  
  <pre><code>def prompt_to_activate(bear, printer):
      PROMPT_TO_ACTIVATE_STR = ('program has found {} to be useful '
                                'based of dependencies discovered from your '
                                'project files. \n Would you like to activate '
                                'it? (y/n)')
      printer.print(PROMPT_TO_ACTIVATE_STR)
  
      choice = input().lower()
  
      if choice.startswith('y'):
          return True
      elif choice.startswith('n'):
          return False
      else:
          return prompt_to_activate(bear, printer)
  for i in range(0, 3):
      a = i
  print(a)
  </code></pre>
  
  <p>I tried adding some <code>time.sleep(x)</code> before that statement but that wouldn't fix it. Can somebody tell me the exact reason why this is happening and how to fix it?</p>