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>`_
- `@cgoldberg <https://github.com/cgoldberg>`_
- `@ereOn <https://github.com/ereOn>`_
- `@HaraldNordgren <https://github.com/HaraldNordgren>`_

View File

@ -1,3 +1,4 @@
import json
import logging
import os
import re
@ -6,12 +7,17 @@ import timeit
from nose.plugins import Plugin
# try to import Queue
try:
import Queue
except ImportError:
import queue as Queue
try:
from collections import OrderedDict
except ImportError:
from ordereddict import OrderedDict
# define constants
IS_NT = os.name == 'nt'
@ -149,10 +155,11 @@ class TimerPlugin(Plugin):
d = sorted(self._timed_tests.items(),
key=lambda item: item[1]['time'],
reverse=True)
if self.json_file:
import json
dict_type = OrderedDict if self.timer_top_n else dict
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])

View File

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