Skip to content

Instantly share code, notes, and snippets.

@kylemcc
Forked from stantonk/slowtest.py
Last active December 23, 2015 18:39
Show Gist options
  • Save kylemcc/6677279 to your computer and use it in GitHub Desktop.
Save kylemcc/6677279 to your computer and use it in GitHub Desktop.
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