When using '--timer-top-n', output the '--timer-json-file' results with slowest tests first
This commit is contained in:
parent
2a3870fa1b
commit
ccc4dacd1d
|
@ -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>`_
|
||||
|
|
|
@ -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])
|
||||
|
||||
|
|
Loading…
Reference in New Issue