Skip to content

Instantly share code, notes, and snippets.

@juanpabloaj
Created June 22, 2014 01:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanpabloaj/04f7894ebbd4c4cc7929 to your computer and use it in GitHub Desktop.
Save juanpabloaj/04f7894ebbd4c4cc7929 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
# python -m unittest test_output
import sys
import unittest
from StringIO import StringIO
def hello():
print 'hello world'
class OutTest(unittest.TestCase):
def setUp(self):
self.output = StringIO()
self.saved_stdout = sys.stdout
sys.stdout = self.output
def tearDown(self):
self.output.close()
sys.stdout = self.saved_stdout
def testOut(self):
hello()
self.assertEqual(self.output.getvalue(), 'hello world\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment