擅长:python、mysql、java
<p>正如我在注释中所解释的,<code>buffer</code>只是缓冲测试代码的输出。这意味着您只能从<code>unittest2</code>本身获得输出。它工作得很好。(在您的例子中,它的工作也很简单,您的代码不会打印出任何内容,因此缓冲区与缓冲区之间没有任何内容,这就是为什么没有它,您会得到相同的结果。)</p>
<p>如果您也不想从<code>unittest2</code>获得任何输出,则可以始终使用重定向到<code>/dev/null</code>的shell命令行运行该脚本,或者从重定向到<code>sys.stdout</code>的脚本导入<code>unittest2</code>。</p>
<p>但通常你真的想读那个标准输出,而不仅仅是丢弃它。即使你不想把它记录在任何地方,你也要检查最后一行是否是<code>"OK"</code>,这样你就可以向你的编程团队发送电击,或者在失败时执行任何操作。否则,通过<code>cron</code>运行测试有什么意义?</p>