def __start_capture(self): """ __start_capture and __end_capture bracket a zone of time that we might want to dump captured information from. E.G. we normally don't WANT to see stdout and stderr from "test_did_this_work()"... unless they fail. In which case, we want to see them! Both capture and logcapture report all this at the END of the entire run, however. This is great and very handy (since they are all there at the end of the run). But, in the context of looking at a single test, it's really annoying. So, this logic is stolen from the xunit plugin (which does capture better than capture!). We are basically tucking away stdout/stderrs while letting the data flow to prior levels using the Tee. """ self.__capture_stack.append((sys.stdout, sys.stderr)) self.__current_stdout = StringIO() self.__current_stderr = StringIO() sys.stdout = Tee(self.encoding, self.__current_stdout, sys.stdout) sys.stderr = Tee(self.encoding, self.__current_stderr, sys.stderr)
def setUp(self): self.orig_stderr = sys.stderr sys.stderr = Tee('utf-8', self.orig_stderr)
def test_tee_has_error_and_encoding_attributes(self): tee = Tee('utf-8', sys.stdout) self.assertTrue(hasattr(tee, 'encoding')) self.assertTrue(hasattr(tee, 'errors'))
def _startCapture(self): self._capture_stack.append((sys.stdout, sys.stderr)) self._currentStdout = StringIO() self._currentStderr = StringIO() sys.stdout = Tee(self._currentStdout, sys.stdout) sys.stderr = Tee(self._currentStderr, sys.stderr)