How to test?

Terry Reedy tjreedy at udel.edu
Fri Jun 19 12:23:16 EDT 2020


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



More information about the Python-list mailing list