Mercurial > hg
changeset 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 | 37d7cf569cf3 |
children | e9f099ede405 |
files | .hgignore tests/run-tests.py |
diffstat | 2 files changed, 45 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Sun Dec 20 11:56:24 2015 -0800 +++ b/.hgignore Mon Jan 04 21:54:44 2016 -0800 @@ -20,6 +20,7 @@ \#*\# .\#* tests/.coverage* +tests/.testtimes* tests/annotated tests/*.err tests/htmlcov
--- a/tests/run-tests.py Sun Dec 20 11:56:24 2015 -0800 +++ b/tests/run-tests.py Mon Jan 04 21:54:44 2016 -0800 @@ -1601,6 +1601,49 @@ return result +# Save the most recent 5 wall-clock runtimes of each test to a +# human-readable text file named .testtimes. Tests are sorted +# alphabetically, while times for each test are listed from oldest to +# newest. + +def loadtimes(testdir): + times = [] + try: + with open(os.path.join(testdir, '.testtimes-')) as fp: + for line in fp: + ts = line.split() + times.append((ts[0], [float(t) for t in ts[1:]])) + except IOError as err: + if err.errno != errno.ENOENT: + raise + return times + +def savetimes(testdir, result): + saved = dict(loadtimes(testdir)) + maxruns = 5 + skipped = set([str(t[0]) for t in result.skipped]) + for tdata in result.times: + test, real = tdata[0], tdata[3] + if test not in skipped: + ts = saved.setdefault(test, []) + ts.append(real) + ts[:] = ts[-maxruns:] + + fd, tmpname = tempfile.mkstemp(prefix='.testtimes', + dir=testdir, text=True) + with os.fdopen(fd, 'w') as fp: + for name, ts in sorted(saved.iteritems()): + fp.write('%s %s\n' % (name, ' '.join(['%.3f' % (t,) for t in ts]))) + timepath = os.path.join(testdir, '.testtimes') + try: + os.unlink(timepath) + except OSError: + pass + try: + os.rename(tmpname, timepath) + except OSError: + pass + class TextTestRunner(unittest.TextTestRunner): """Custom unittest test runner that uses appropriate settings.""" @@ -1697,6 +1740,7 @@ self._runner._checkhglib('Tested') + savetimes(self._runner._testdir, result) self.stream.writeln( '# Ran %d tests, %d skipped, %d warned, %d failed.' % (result.testsRun,