When using '--timer-top-n', output the '--timer-json-file' results with slowest tests first

This commit is contained in:
Harald Nordgren
2016-10-23 03:21:00 +02:00
committed by Stanislav
parent 2a3870fa1b
commit ccc4dacd1d
3 changed files with 13 additions and 3 deletions

View File

@@ -143,3 +143,4 @@ Contributors
- `@hugovk <https://github.com/hugovk>`_ - `@hugovk <https://github.com/hugovk>`_
- `@cgoldberg <https://github.com/cgoldberg>`_ - `@cgoldberg <https://github.com/cgoldberg>`_
- `@ereOn <https://github.com/ereOn>`_ - `@ereOn <https://github.com/ereOn>`_
- `@HaraldNordgren <https://github.com/HaraldNordgren>`_

View File

@@ -1,3 +1,4 @@
import json
import logging import logging
import os import os
import re import re
@@ -6,12 +7,17 @@ import timeit
from nose.plugins import Plugin from nose.plugins import Plugin
# try to import Queue
try: try:
import Queue import Queue
except ImportError: except ImportError:
import queue as Queue import queue as Queue
try:
from collections import OrderedDict
except ImportError:
from ordereddict import OrderedDict
# define constants # define constants
IS_NT = os.name == 'nt' IS_NT = os.name == 'nt'
@@ -149,10 +155,11 @@ class TimerPlugin(Plugin):
d = sorted(self._timed_tests.items(), d = sorted(self._timed_tests.items(),
key=lambda item: item[1]['time'], key=lambda item: item[1]['time'],
reverse=True) reverse=True)
if self.json_file: if self.json_file:
import json dict_type = OrderedDict if self.timer_top_n else dict
with open(self.json_file, 'w') as f: with open(self.json_file, 'w') as f:
json.dump({'tests': dict((k, v) for k, v in d)}, f) json.dump({'tests': dict_type((k, v) for k, v in d)}, f)
total_time = sum([vv['time'] for kk, vv in d]) total_time = sum([vv['time'] for kk, vv in d])

View File

@@ -20,12 +20,14 @@ setup(
'Stanislav Kudriashev', 'Stanislav Kudriashev',
'Raoul Snyman', 'Raoul Snyman',
'Corey Goldberg', 'Corey Goldberg',
'Harald Nordgren',
]), ]),
url='https://github.com/mahmoudimus/nose-timer', url='https://github.com/mahmoudimus/nose-timer',
packages=['nosetimer', ], packages=['nosetimer', ],
install_requires=[ install_requires=[
'nose', 'nose',
'termcolor', 'termcolor',
'ordereddict',
], ],
license='MIT or BSD', license='MIT or BSD',
entry_points={ entry_points={