Python 检查是否打印了内容

Python 检查是否打印了内容,python,python-3.x,printing,stream,Python,Python 3.x,Printing,Stream,有没有办法检查我的python程序是否将某些内容打印到特定的流中?对于Python3.x,您可以试试 print('print this stuff') import sys sys.stdout.write('print this stuff') 你是说有小溪吗?不仅仅是stdout?特别是stdout和stderr。但这只会打印到流写入。我怎么检查?我的情况更像是,我想要一个测试来检查打印的东西与否。

有没有办法检查我的python程序是否将某些内容打印到特定的流中?

对于Python3.x,您可以试试

print('print this stuff')


import sys
sys.stdout.write('print this stuff')

你是说有小溪吗?不仅仅是stdout?特别是stdout和stderr。但这只会打印到流写入。我怎么检查?我的情况更像是,我想要一个测试来检查打印的东西与否。