~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/__init__.py

  • Committer: Robert Collins
  • Date: 2005-10-11 08:05:45 UTC
  • mto: This revision was merged to the branch mainline in revision 1444.
  • Revision ID: robertc@lifelesslap.robertcollins.net-20051011080545-daa592731b2c0a15
make selftest -v show the elapsed time for each test run.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import unittest
21
21
import tempfile
22
22
import os
23
 
import sys
24
23
import errno
 
24
import re
 
25
import shutil
25
26
import subprocess
26
 
import shutil
27
 
import re
 
27
import sys
 
28
import time
28
29
 
29
30
import bzrlib.commands
30
31
import bzrlib.trace
70
71
    No special behaviour for now.
71
72
    """
72
73
 
 
74
    def _elapsedTime(self):
 
75
        return "(Took %.3fs)" % (time.time() - self._start_time)
 
76
 
73
77
    def startTest(self, test):
74
78
        unittest.TestResult.startTest(self, test)
75
79
        # TODO: Maybe show test.shortDescription somewhere?
77
81
        if self.showAll:
78
82
            self.stream.write('%-70.70s' % what)
79
83
        self.stream.flush()
 
84
        self._start_time = time.time()
80
85
 
81
86
    def addError(self, test, err):
82
 
        super(_MyResult, self).addError(test, err)
 
87
        unittest.TestResult.addError(self, test, err)
 
88
        if self.showAll:
 
89
            self.stream.writeln("ERROR %s" % self._elapsedTime())
 
90
        elif self.dots:
 
91
            self.stream.write('E')
83
92
        self.stream.flush()
84
93
 
85
94
    def addFailure(self, test, err):
86
 
        super(_MyResult, self).addFailure(test, err)
 
95
        unittest.TestResult.addFailure(self, test, err)
 
96
        if self.showAll:
 
97
            self.stream.writeln("FAIL %s" % self._elapsedTime())
 
98
        elif self.dots:
 
99
            self.stream.write('F')
87
100
        self.stream.flush()
88
101
 
89
102
    def addSuccess(self, test):
90
103
        if self.showAll:
91
 
            self.stream.writeln('OK')
 
104
            self.stream.writeln('OK %s' % self._elapsedTime())
92
105
        elif self.dots:
93
106
            self.stream.write('~')
94
107
        self.stream.flush()