On 6/17/2020 12:34 PM, Tony Flury via Python-list wrote:

In a recent application that I wrote (where output to the console was important), I tested it using the 'unittest' framework, and by patching sys.stderr to be a StringIO - that way my test case could inspect what was being output.

Tony's code with hard returns added so that code lines remain separated instead of wrapping.

with patch('sys.stderr', StringIO()) as stderr:
application.do_stuff() self.assertTrue(stderr.getvalue(), 'Woops - that didn\'t work')
This doc, worth reading more than once, is
https://docs.python.org/3/library/unittest.mock.html#the-patchers

--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to