~gmb/zope.testing/moar-redirection

« back to all changes in this revision

Viewing changes to src/zope/testing/testrunner/formatter.py

  • Committer: Graham Binns
  • Date: 2012-05-30 12:06:08 UTC
  • Revision ID: graham@canonical.com-20120530120608-c67aiz9tnzusdyhf
Reverted the reversion of the redirection code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
682
682
    content = None
683
683
 
684
684
 
 
685
class Stream(object):
 
686
 
 
687
    def __init__(self, output=None, error=None):
 
688
        self._output = sys.__stdout__ if output is None else output
 
689
        self._error = sys.__stderr__ if error is None else error
 
690
        # Redirect all stdout output to stderror. We'll use
 
691
        # self._output for writes so that they still go to the real
 
692
        # stdout.
 
693
        sys.stdout = self._error
 
694
 
 
695
    def __getattr__(self, name):
 
696
        return getattr(self._output, name)
 
697
 
 
698
    def cleanup(self):
 
699
        # Clean up our monkeypatches.
 
700
        sys.stdout = sys.__stdout__
 
701
 
 
702
    def close(self):
 
703
        self.cleanup()
 
704
        sys.stdout.close()
 
705
 
 
706
 
685
707
class SubunitOutputFormatter(object):
686
708
    """A subunit output formatter.
687
709
 
721
743
        self.options = options
722
744
 
723
745
        if stream is None:
724
 
            stream = sys.stdout
 
746
            stream = Stream()
725
747
        self._stream = stream
726
748
        self._subunit = subunit.TestProtocolClient(self._stream)
727
749