On Sat, 25 Apr 2020 08:25:00 +1200 DL Neil <pythonl...@danceswithmice.info> wrote:
> 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 > > This is interesing. > 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! > Logging wouldn't help here as the person running the program is competent, and it likes to see what the errors are. -- Manfred -- https://mail.python.org/mailman/listinfo/python-list