unitest with python curses app
David M. Cooke
cookedm+news at physics.mcmaster.ca
Fri Feb 20 16:52:07 EST 2004
At some point, Brian <balex at sympatico.ca> wrote:
> Hello;
>
> I'm writing a program with curses in python and having a bit of trouble
> understanding how to use unittest. So far, I have used testing
> successfully -- as long as the report goes to stdout (or does unittest
> write to stderr?)
I'm interested: how are you unit testing curses routines? Are you
testing just the output routines, or are other non-curses routines
being called?
> The curses part of the program seems to affect unittest's writing of the
> report. The screen is not what the report expects, so a lot of
> information is in the wrong place after the program exits. (I actually wrap
> the calls into the
> curses library with curses.wrapper() in an attempt to restore the display
> properly after the program exits -- to no avail. I guess the problem is
> that unittest writes to the display while curses has control, not just
> just afterwards.
Right. Pain in the ass to debug that stuff too.
> How do I handle test reporting for a graphical (curses) application? I
> would really like to read or capture the report on screen after the
> program exits.
Probably setting sys.stdout and sys.stderr to your own file objects
would work before calling unittest.main(). Something like this would
give the output after it runs:
import sys
from cStringIO import StringIO
import unittest
...test cases...
if __name__ == '__main__':
old_stdout, old_stderr = sys.stdout, sys.stderr
sys.stdout = StringIO()
sys.stderr = StringIO()
unittest.main()
old_stdout.write(sys.stdout.getvalue())
old_stderr.write(sys.stderr.getvalue())
--
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
More information about the Python-list
mailing list