def captured_stdout():
return captured_output("<STR_LIT>")<EOL>
Capture the output of sys.stdout:

       with captured_stdout() as s:
           print "hello"
       self.assertEqual(s.getvalue(), "hello")