测试标准流(stdout,stderr)输出的python unittest.testcase
streamtest的Python项目详细描述
概述
streamtest为 测试标准流的输出(stdout,stderr)。
用法
fromstramtestimportCatchStreamTestCaseclassStreamTestCase(CatchStreamTestCase):deftest_stdout(self):withself.catch_stream("stdout")asstream:print"hello world"self.assertEqual(stream,"hello world\n")deftest_stderr(self):withself.catch_stream("stderr")asstream:sys.stderr.write("Error!")self.assertEqual(stream,"Error!")
安装
$ pip install streamtest
或
$ git clone git@github.com:alice1017/streamtest.git $ cd streamtest $ python setup.py build install