The streamtest provides the enhanced unittest.TestCase
for
testing the output of standard stream (stdout
, stderr
).
from stramtest import CatchStreamTestCase
class StreamTestCase(CatchStreamTestCase):
def test_stdout(self):
with self.catch_stream("stdout") as stream:
print "hello world"
self.assertEqual(stream, "hello world\n")
def test_stderr(self):
with self.catch_stream("stderr") as stream:
sys.stderr.write("Error!")
self.assertEqual(stream, "Error!")
$ pip install streamtest
or
$ git clone git@github.com:alice1017/streamtest.git $ cd streamtest $ python setup.py build install