-
-
Save kylemcc/6677279 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
if 'test' in sys.argv: | |
import django.test | |
import time | |
class TimedTestCase(django.test.TestCase): | |
_TOO_LONG = 0.100 | |
def run(self, *args, **kwargs): | |
_start = time.time() | |
super(TimedTestCase, self).run(*args, **kwargs) | |
slow_test = '\nSLOW TEST: %s took %.3f' | |
reminder = '\nTODO: add call to super setUp() method in %s' | |
if _start is not None: | |
duration = time.time() - _start | |
if duration > self._TOO_LONG: | |
print slow_test % (self.id(), duration) | |
# Cause test to fail if it takes too long | |
#try: | |
# self.fail('Test took too long. Took: %.3f ' | |
# 'Threshold: %.3f' % (duration, self._TOO_LONG)) | |
# except Exception: | |
# result.addFailure(self, sys.exc_info()) | |
else: | |
#print reminder % self.id() | |
pass | |
django.test.TestCase = TimedTestCase |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment