On 25/04/20 6:40 AM, 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?

Yes, as well as reproducing the output on-screen, there are now three ways to deal with stdout. The newest is "tee", which like the Linux command of the same name, gives the best of both worlds - display and 'capture'!

Capturing of the stdout/stderr output
https://docs.pytest.org/en/latest/capture.html


May I point-out that the above may not be the best approach. Rather than using screen-prints to report errors, another method is to utilise "logging" to collect such data - so that there is always a formal record (regardless of user behavior). During 'production' the information could be collected at some central 'location' for inspection by competent staff. During 'development', it is possible, by changing one line, to re-direct the log to wherever you would like - including the above!

Python library: https://docs.python.org/3/library/logging.html
Logging (testing): https://docs.pytest.org/en/latest/logging.html
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to