~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/__init__.py

  • Committer: Martin Pool
  • Date: 2005-06-22 07:30:45 UTC
  • Revision ID: mbp@sourcefrog.net-20050622073045-80d336b7e0b859aa
- redirect stdout/stderr while running tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
121
121
 
122
122
    No special behaviour for now.
123
123
    """
 
124
    def __init__(self, out):
 
125
        self.out = out
 
126
        TestResult.__init__(self)
 
127
 
124
128
    def startTest(self, test):
125
129
        # TODO: Maybe show test.shortDescription somewhere?
126
 
        print '%-60.60s' % test.id(),
 
130
        print >>self.out, '%-60.60s' % test.id(),
127
131
        TestResult.startTest(self, test)
128
132
 
129
133
    def stopTest(self, test):
132
136
 
133
137
 
134
138
    def addError(self, test, err):
135
 
        print 'ERROR'
 
139
        print >>self.out, 'ERROR'
136
140
        TestResult.addError(self, test, err)
137
141
 
138
142
    def addFailure(self, test, err):
139
 
        print 'FAILURE'
 
143
        print >>self.out, 'FAILURE'
140
144
        TestResult.addFailure(self, test, err)
141
145
 
142
146
    def addSuccess(self, test):
143
 
        print 'OK'
 
147
        print >>self.out, 'OK'
144
148
        TestResult.addSuccess(self, test)
145
149
 
146
150
 
155
159
    import os
156
160
    import shutil
157
161
    import time
 
162
    import sys
158
163
 
159
164
    _setup_test_log()
160
165
    _setup_test_dir()
173
178
            bzrlib.commands:
174
179
        suite.addTest(DocTestSuite(m))
175
180
 
176
 
    result = _MyResult()
177
 
    suite.run(result)
 
181
    # save stdout & stderr so there's no leakage from code-under-test
 
182
    real_stdout = sys.stdout
 
183
    real_stderr = sys.stderr
 
184
    sys.stdout = sys.stderr = TestBase.TEST_LOG
 
185
    try:
 
186
        result = _MyResult(real_stdout)
 
187
        suite.run(result)
 
188
    finally:
 
189
        sys.stdout = real_stdout
 
190
        sys.stderr = real_stderr
178
191
 
179
192
    _show_results(result)
180
193
 
181
194
    return result.wasSuccessful()
182
195
 
183
196
 
 
197
 
 
198
 
184
199
def _setup_test_log():
185
200
    import time
186
201
    import os