from django.test.runner import DiscoverRunner

from unittest.runner import TextTestRunner, TextTestResult
from time import time


class TimedTextTestResult(TextTestResult):

    def __init__(self, *args, **kwargs):
        super(TimedTextTestResult, self).__init__(*args, **kwargs)
        self.clocks = dict()
        self.max_time = 0
        self.black_sheep = ""

    def startTest(self, test):
        self.clocks[test] = time()
        super(TextTestResult, self).startTest(test)
        if self.showAll:
            self.stream.write(self.getDescription(test))
            self.stream.write(" ... ")
            self.stream.flush()

    def addSuccess(self, test):
        super(TextTestResult, self).addSuccess(test)
        if self.showAll:
            duration = time() - self.clocks[test]
            self.stream.writeln("ok (%.6fs)" % (duration))
            if duration > self.max_time:
                self.max_time = duration
                self.black_sheep = test
        elif self.dots:
            self.stream.write('.')
            self.stream.flush()


class TimedTextTestRunner(TextTestRunner):
    resultclass = TimedTextTestResult

    def run(self, test):
        result = super(TimedTextTestRunner, self).run(test)
        self.stream.writeln("Longest test : %s" % result.black_sheep)
        return result


class TestRunner(DiscoverRunner):
    test_runner = TimedTextTestRunner

@@ -321,50 +321,19 @@
 elf.
-max_time = 0%0A        self.black_
 sheep
+s
  = 
-%22%22
+%7B%7D
 %0A%0A  
@@ -837,117 +837,36 @@
     
-if duration %3E self.max_time:%0A                self.max_time = duration%0A                self.black_sheep = test
+self.sheeps%5Btest%5D = duration
 %0A   
@@ -1134,57 +1134,247 @@
     
-self.stream.writeln(%22Longest test
+black_sheeps = %5B%5Bk, v%5D for k, v in sorted(result.sheeps.items(), key=lambda item: item%5B1%5D)%5D%5B-10:%5D%0A        self.stream.writeln(%22Top 10 : %5Cn%22)%0A        for black_sheep in black_sheeps%5B::-1%5D:%0A            self.stream.writeln(%22%25s
  : %25s
+ s
 %22 %25 
-result.
+(str(
 blac
@@ -1380,16 +1380,37 @@
 ck_sheep
+%5B0%5D), black_sheep%5B1%5D)
 )%0A      

Add top 10