##// END OF EJS Templates
run-tests: '--time' option provide more details to Linux users...
anuraggoel -
r21977:4ca4e157 default
parent child Browse files
Show More
@@ -1077,6 +1077,7 b' class TestResult(unittest._TextTestResul'
1077
1077
1078 self.times = []
1078 self.times = []
1079 self._started = {}
1079 self._started = {}
1080 self._stopped = {}
1080
1081
1081 def addFailure(self, test, reason):
1082 def addFailure(self, test, reason):
1082 self.failures.append((test, reason))
1083 self.failures.append((test, reason))
@@ -1167,17 +1168,28 b' class TestResult(unittest._TextTestResul'
1167 def startTest(self, test):
1168 def startTest(self, test):
1168 super(TestResult, self).startTest(test)
1169 super(TestResult, self).startTest(test)
1169
1170
1170 self._started[test.name] = time.time()
1171 # os.times module computes the user time and system time spent by
1172 # child's processes along with real elapsed time taken by a process.
1173 # This module has one limitation. It can only work for Linux user
1174 # and not for Windows.
1175 self._started[test.name] = os.times()
1171
1176
1172 def stopTest(self, test, interrupted=False):
1177 def stopTest(self, test, interrupted=False):
1173 super(TestResult, self).stopTest(test)
1178 super(TestResult, self).stopTest(test)
1174
1179
1175 self.times.append((test.name, time.time() - self._started[test.name]))
1180 self._stopped[test.name] = os.times()
1181
1182 starttime = self._started[test.name]
1183 endtime = self._stopped[test.name]
1184 self.times.append((test.name, endtime[2] - starttime[2],
1185 endtime[3] - starttime[3], endtime[4] - starttime[4]))
1186
1176 del self._started[test.name]
1187 del self._started[test.name]
1188 del self._stopped[test.name]
1177
1189
1178 if interrupted:
1190 if interrupted:
1179 self.stream.writeln('INTERRUPTED: %s (after %d seconds)' % (
1191 self.stream.writeln('INTERRUPTED: %s (after %d seconds)' % (
1180 test.name, self.times[-1][1]))
1192 test.name, self.times[-1][3]))
1181
1193
1182 class TestSuite(unittest.TestSuite):
1194 class TestSuite(unittest.TestSuite):
1183 """Custom unitest TestSuite that knows how to execute Mercurial tests."""
1195 """Custom unitest TestSuite that knows how to execute Mercurial tests."""
@@ -1348,11 +1360,12 b' class TextTestRunner(unittest.TextTestRu'
1348
1360
1349 def printtimes(self, times):
1361 def printtimes(self, times):
1350 self.stream.writeln('# Producing time report')
1362 self.stream.writeln('# Producing time report')
1351 times.sort(key=lambda t: (t[1], t[0]), reverse=True)
1363 times.sort(key=lambda t: (t[3]))
1352 cols = '%7.3f %s'
1364 cols = '%7.3f %7.3f %7.3f %s'
1353 self.stream.writeln('%-7s %s' % ('Time', 'Test'))
1365 self.stream.writeln('%-7s %-7s %-7s %s' % ('cuser', 'csys', 'real',
1354 for test, timetaken in times:
1366 'Test'))
1355 self.stream.writeln(cols % (timetaken, test))
1367 for test, cuser, csys, real in times:
1368 self.stream.writeln(cols % (cuser, csys, real, test))
1356
1369
1357 class TestRunner(object):
1370 class TestRunner(object):
1358 """Holds context for executing tests.
1371 """Holds context for executing tests.
@@ -201,3 +201,23 b' No Diff'
201 # Ran 2 tests, 0 skipped, 0 warned, 1 failed.
201 # Ran 2 tests, 0 skipped, 0 warned, 1 failed.
202 python hash seed: * (glob)
202 python hash seed: * (glob)
203 [1]
203 [1]
204
205 test for --time
206 ==================
207
208 $ $TESTDIR/run-tests.py --with-hg=`which hg` test-success.t --time
209 .
210 # Ran 1 tests, 0 skipped, 0 warned, 0 failed.
211 # Producing time report
212 cuser csys real Test
213 \s*[\d\.]{5} \s*[\d\.]{5} \s*[\d\.]{5} test-success.t (re)
214
215 test for --time with --job enabled
216 ====================================
217
218 $ $TESTDIR/run-tests.py --with-hg=`which hg` test-success.t --time --jobs 2
219 .
220 # Ran 1 tests, 0 skipped, 0 warned, 0 failed.
221 # Producing time report
222 cuser csys real Test
223 \s*[\d\.]{5} \s*[\d\.]{5} \s*[\d\.]{5} test-success.t (re)
General Comments 0
You need to be logged in to leave comments. Login now