I am using an extension of python's unittest, unittest-xml-reporting. It currently captures stdout and stores it in the xml output file. Awesome! But, I also want to echo it to the screen so I don't have to view that file every time I run my test suite. The two main functions involved are:
def _patch_standard_output(self):
"""Replace the stdout and stderr streams with string-based streams
in order to capture the tests' output.
"""
(self.old_stdout, self.old_stderr) = (sys.stdout, sys.stderr)
(sys.stdout, sys.stderr) = (self.stdout, self.stderr) = \
(StringIO(), StringIO())
def _restore_standard_output(self):
"Restore the stdout and stderr streams."
(sys.stdout, sys.stderr) = (self.old_stdout, self.old_stderr)
I tried removing the
(sys.stdout, sys.stderr) = (self.stdout, self.stderr) = (StringIO(), StringIO())
and replace it with
(self.stdout, self.stderr) = (StringIO(), StringIO())
but then it did not add it to the xml file. Any help is appreciated. I'll be glad to submit a pull request when I get it working too!