title: Python 2.7 -- have test script simulate raw_input
body: <p>I'm using Python 2.7 to create a game.  I want to use a test script to check the methods in my main file, but I'm running into a slight issue.</p>
  
  <p>In the main script, I ask if the user wants to play the game, using <code>raw_input()</code>.  Unfortunately, this means that when I run the test script using Windows PowerShell, the console asks the user for input and I have to manually type an answer.  With repeated testing, manual typing is getting tedious.</p>
  
  <p>(MWE and output below: Here, the test script should generate a 'n' because it's only checking the method, and not the gameplay itself.  The actual method does some calculation, prints a statement, and outputs a string.)</p>
  
  <p>This brings me to my question:
  <strong><em>Is there some way to write a test script that will automatically generate an input for <code>raw_input()</code>?</em>
  <em>Alternately, is there some other way to accept user input in the main game file that the test script can simulate?</em></strong></p>
  
  <p><em>Thoughts:</em> While searching for an answer, I've seen some information about <code>mock</code>...I haven't used that before and also mock seems to assert an outcome from a particular statement, but I just want the test file to effectively bypass that prompt.  I could just remove that (y/n) prompt from the game script, but this seems like a good learning opportunity...</p>
  
  <p>MWE.py (the game file)</p>
  
  <pre><code>def game_method(stuff):
      """Calculates stuff for game"""
      stuff_out = 'foo'
      return stuff_out
  
  """ Check user wants to play the game """
  startCheck = raw_input('Would you like to play the game? (y/n) &gt; ')
  if (startCheck.lower() == 'y'):
      play = True
  else:
      play = False
  
  """ Set up a game to play"""
  while (play==True):
      # Do stuff
      stuff_out = game_method(stuff)
  else:
      print "\n\tGoodbye.\n\n"
  </code></pre>
  
  <p>MWE-test.py (the test script)</p>
  
  <pre><code>import MWE
  
  def check_game(input):
      string_out = MWE.game_method(input)
      return string_out
  
  """ Test code here """
  input = 7
  string_output = check_game(input)
  print "===============\n%s\n===============\n\n\n" % (string_output == 'foo')
  </code></pre>
  
  <p>Console output:</p>
  
  <pre><code>PS C:\dir&gt; python MWE-test.py
  Would you like to play the game? (y/n) &gt; n
  
          Goodbye.
  
  
  ===True===
  
  PS C:\dir&gt;
  </code></pre>