Show More
@@ -20,6 +20,7 b' syntax: glob' | |||||
20 | \#*\# |
|
20 | \#*\# | |
21 | .\#* |
|
21 | .\#* | |
22 | tests/.coverage* |
|
22 | tests/.coverage* | |
|
23 | tests/.testtimes* | |||
23 | tests/annotated |
|
24 | tests/annotated | |
24 | tests/*.err |
|
25 | tests/*.err | |
25 | tests/htmlcov |
|
26 | tests/htmlcov |
@@ -1601,6 +1601,49 b' class TestSuite(unittest.TestSuite):' | |||||
1601 |
|
1601 | |||
1602 | return result |
|
1602 | return result | |
1603 |
|
1603 | |||
|
1604 | # Save the most recent 5 wall-clock runtimes of each test to a | |||
|
1605 | # human-readable text file named .testtimes. Tests are sorted | |||
|
1606 | # alphabetically, while times for each test are listed from oldest to | |||
|
1607 | # newest. | |||
|
1608 | ||||
|
1609 | def loadtimes(testdir): | |||
|
1610 | times = [] | |||
|
1611 | try: | |||
|
1612 | with open(os.path.join(testdir, '.testtimes-')) as fp: | |||
|
1613 | for line in fp: | |||
|
1614 | ts = line.split() | |||
|
1615 | times.append((ts[0], [float(t) for t in ts[1:]])) | |||
|
1616 | except IOError as err: | |||
|
1617 | if err.errno != errno.ENOENT: | |||
|
1618 | raise | |||
|
1619 | return times | |||
|
1620 | ||||
|
1621 | def savetimes(testdir, result): | |||
|
1622 | saved = dict(loadtimes(testdir)) | |||
|
1623 | maxruns = 5 | |||
|
1624 | skipped = set([str(t[0]) for t in result.skipped]) | |||
|
1625 | for tdata in result.times: | |||
|
1626 | test, real = tdata[0], tdata[3] | |||
|
1627 | if test not in skipped: | |||
|
1628 | ts = saved.setdefault(test, []) | |||
|
1629 | ts.append(real) | |||
|
1630 | ts[:] = ts[-maxruns:] | |||
|
1631 | ||||
|
1632 | fd, tmpname = tempfile.mkstemp(prefix='.testtimes', | |||
|
1633 | dir=testdir, text=True) | |||
|
1634 | with os.fdopen(fd, 'w') as fp: | |||
|
1635 | for name, ts in sorted(saved.iteritems()): | |||
|
1636 | fp.write('%s %s\n' % (name, ' '.join(['%.3f' % (t,) for t in ts]))) | |||
|
1637 | timepath = os.path.join(testdir, '.testtimes') | |||
|
1638 | try: | |||
|
1639 | os.unlink(timepath) | |||
|
1640 | except OSError: | |||
|
1641 | pass | |||
|
1642 | try: | |||
|
1643 | os.rename(tmpname, timepath) | |||
|
1644 | except OSError: | |||
|
1645 | pass | |||
|
1646 | ||||
1604 | class TextTestRunner(unittest.TextTestRunner): |
|
1647 | class TextTestRunner(unittest.TextTestRunner): | |
1605 | """Custom unittest test runner that uses appropriate settings.""" |
|
1648 | """Custom unittest test runner that uses appropriate settings.""" | |
1606 |
|
1649 | |||
@@ -1697,6 +1740,7 b' class TextTestRunner(unittest.TextTestRu' | |||||
1697 |
|
1740 | |||
1698 | self._runner._checkhglib('Tested') |
|
1741 | self._runner._checkhglib('Tested') | |
1699 |
|
1742 | |||
|
1743 | savetimes(self._runner._testdir, result) | |||
1700 | self.stream.writeln( |
|
1744 | self.stream.writeln( | |
1701 | '# Ran %d tests, %d skipped, %d warned, %d failed.' |
|
1745 | '# Ran %d tests, %d skipped, %d warned, %d failed.' | |
1702 | % (result.testsRun, |
|
1746 | % (result.testsRun, |
General Comments 0
You need to be logged in to leave comments.
Login now