title: Python: Write unittest for console print
body: <p>Function <code>foo</code> prints to console. I want to test the console print. How can I achieve this in python?</p>
  
  <p>Need to test this function, has NO return statement : </p>
  
  <pre><code>def foo(inStr):
     print "hi"+inStr
  </code></pre>
  
  <p>My test : </p>
  
  <pre><code>def test_foo():
      cmdProcess = subprocess.Popen(foo("test"), stdout=subprocess.PIPE)
      cmdOut = cmdProcess.communicate()[0]
      self.assertEquals("hitest", cmdOut)
  </code></pre>