Created
February 19, 2014 19:02
-
-
Save slinkp/9099165 to your computer and use it in GitHub Desktop.
Patch pinocchio nose plugin to report slowest N tests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -u -r /usr/local/lib/python2.7/dist-packages/pinocchio/stopwatch.py /home/vagrant/tmp/pinocchio/stopwatch.py | |
--- /usr/local/lib/python2.7/dist-packages/pinocchio/stopwatch.py 2014-02-19 18:55:30.000000000 +0000 | |
+++ /home/vagrant/tmp/pinocchio/stopwatch.py 2014-02-19 18:50:40.064935116 +0000 | |
@@ -37,6 +37,14 @@ | |
default=".nose-stopwatch-times", | |
help="Store test timing results in this file.") | |
+ parser.add_option("--stopwatch-report-slowest", | |
+ action="store", | |
+ dest="stopwatch_report_slowest", | |
+ default=0, | |
+ type="int", | |
+ help="Report the slowest N tests.") | |
+ | |
+ | |
def configure(self, options, config): | |
### configure logging | |
logger = logging.getLogger(__name__) | |
@@ -53,6 +61,7 @@ | |
self.stopwatch_file = os.path.abspath(options.stopwatch_file) | |
self.faster_than = options.faster_than | |
+ self.stopwatch_report_slowest = options.stopwatch_report_slowest | |
log.info('stopwatch module: using "%s" for stopwatch times' % \ | |
(self.stopwatch_file,)) | |
@@ -64,15 +73,14 @@ | |
Run before any of the tests run. Loads the stopwatch file, and | |
calculates which tests should NOT be run. | |
""" | |
- try: | |
- self.times = load(open(self.stopwatch_file)) | |
- except (IOError, EOFError): | |
- self.times = {} | |
- | |
# figure out which tests should NOT be run. | |
faster_than = self.faster_than | |
if faster_than is not None: | |
+ try: | |
+ self.times = load(open(self.stopwatch_file)) | |
+ except (IOError, EOFError): | |
+ pass | |
for (k, v) in list(self.times.items()): | |
if v > faster_than: | |
self.dontrun[k] = 1 | |
@@ -94,6 +102,14 @@ | |
dump(self.times, fp) | |
fp.close() | |
+ def report(self, stream): | |
+ if self.stopwatch_report_slowest: | |
+ slowest = sorted(([v, k] for k, v in self.times.iteritems()), | |
+ reverse=True) | |
+ for value, name in slowest[:self.stopwatch_report_slowest]: | |
+ stream.write("%0.4f: %s\n" % (value, name)) | |
+ | |
+ | |
def wantMethod(self, method): | |
""" | |
Do we want to run this method? See _should_run. | |
@@ -138,3 +154,4 @@ | |
""" | |
runtime = time.time() - self._started | |
self.times[test.test.id()] = runtime | |
+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment