Mercurial > hg
comparison tests/run-tests.py @ 27634:a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
This is an effortless way to track how long each test takes without
having to pass any extra command line options.
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Mon, 04 Jan 2016 21:54:44 -0800 |
parents | 67aa88e00fc7 |
children | e9f099ede405 |
comparison
equal
deleted
inserted
replaced
27633:37d7cf569cf3 | 27634:a1eff44c432b |
---|---|
1599 | 1599 |
1600 channels = [] | 1600 channels = [] |
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 |
1607 def __init__(self, runner, *args, **kwargs): | 1650 def __init__(self, runner, *args, **kwargs): |
1608 super(TextTestRunner, self).__init__(*args, **kwargs) | 1651 super(TextTestRunner, self).__init__(*args, **kwargs) |
1695 finally: | 1738 finally: |
1696 fp.close() | 1739 fp.close() |
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, |
1703 skipped + ignored, warned, failed)) | 1747 skipped + ignored, warned, failed)) |
1704 if failed: | 1748 if failed: |