Last active
December 23, 2015 11:49
-
-
Save stantonk/6631225 to your computer and use it in GitHub Desktop.
Monkeypatch django.test.TestCase to call out slow running tests. Add this in your project's root __init__.py
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
import django.test | |
class TimedTestCase(django.test.TestCase): | |
_TOO_LONG = 0.100 | |
def __init__(self, *args, **kwargs): | |
self._start = None | |
super(TimedTestCase, self).__init__(*args, **kwargs) | |
def setUp(self): | |
self._start = time.time() | |
super(TimedTestCase, self).setUp() | |
def tearDown(self): | |
super(TimedTestCase, self).tearDown() | |
slow_test = '\nSLOW TEST: %s took %.3f' | |
reminder = '\nTODO: add call to super setUp() method in %s' | |
if self._start is not None: | |
duration = time.time() - self._start | |
if duration > self._TOO_LONG: | |
print slow_test % (self.id(), time.time() - self._start) | |
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