Skip to content

Instantly share code, notes, and snippets.

@bulkan
Created June 5, 2012 08:08
Show Gist options
  • Save bulkan/2873524 to your computer and use it in GitHub Desktop.
Save bulkan/2873524 to your computer and use it in GitHub Desktop.
capture unittest output
import sys
import unittest
import StringIO
class DumbestTest(unittest.TestCase):
def test_dumber(self):
self.assertEqual(True, True)
if __name__ == '__main__':
result_stream = StringIO.StringIO()
runner = unittest.TextTestRunner(stream=result_stream, verbosity=2)
my_suite = unittest.TestSuite()
my_suite.addTest(DumbestTest('test_dumber'))
result = runner.run(my_suite)
print int(result.wasSuccessful())
sys.exit(int(result.wasSuccessful()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment