On 24/04/2020 19:40, Manfred Lotz wrote:
I have a command like application which checks a directory tree for
certain things. If there are errors then messages will be written to
stdout.

How to test this in the best way?

One idea was for the error situations to write messages to files and
then later when running the tests to compare the error messages output
to the previously saved output.

Is there anything better?


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.

   with patch('sys.stderr', StringIO()) as
   stderr:application.do_stuff()self.assertTrue(stderr.getvalue(),
   'Woops - that didn\'t work')

I am not sure of the structure of your application, and whether you have a 
callable API that you can invoke.

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

Reply via email to