# HG changeset patch # User Matthieu Laneuville # Date 2017-08-22 09:00:00 # Node ID 4e8a46c25facaebca476634d52dd78431d3143e8 # Parent af20468eb0a499c094dbd6e27ffcacf54cf5a8e6 run-tests: pre instantiate pygments objects Pre instantiate pygments objects to minimize overhead (cf. 20436925e080) diff --git a/tests/run-tests.py b/tests/run-tests.py --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -136,6 +136,9 @@ if pygmentspresent: ] } + runnerformatter = formatters.Terminal256Formatter(style=TestRunnerStyle) + runnerlexer = TestRunnerLexer() + if sys.version_info > (3, 5, 0): PYTHON3 = True xrange = range # we use xrange in one place, and we'd rather not use range @@ -1637,9 +1640,8 @@ class TestResult(unittest._TextTestResul if self.color: formatted = pygments.highlight( formatted, - TestRunnerLexer(), - formatters.Terminal256Formatter( - style=TestRunnerStyle)) + runnerlexer, + runnerformatter) self.stream.write(formatted) self.stream.write('!') @@ -2046,18 +2048,16 @@ class TextTestRunner(unittest.TextTestRu if result.color: formatted = pygments.highlight( formatted, - TestRunnerLexer(), - formatters.Terminal256Formatter( - style=TestRunnerStyle)).strip("\n") + runnerlexer, + runnerformatter).strip("\n") self.stream.writeln(formatted) for test, msg in result.failures: formatted = 'Failed %s: %s' % (test.name, msg) if result.color: formatted = pygments.highlight( formatted, - TestRunnerLexer(), - formatters.Terminal256Formatter( - style=TestRunnerStyle)).strip("\n") + runnerlexer, + runnerformatter).strip("\n") self.stream.writeln(formatted) for test, msg in result.errors: self.stream.writeln('Errored %s: %s' % (test.name, msg))