Sometimes running a test suite can take a long time. This can get especially annoying when you see a failure or error, but have to wait for all the remaining tests to run before you can see the relevant stack traces.
Pressing ctrl+c to interrupt the tests does not work; the KeyboardInterrupt exception does not get caught and only a stack trace irrelevant to your tests is produced.
This behavior can be altered through overriding the testcase's
run method and catching the exception yourself. Now you can stop the tests whenever you want to and still see what is wrong with your tests.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
from django.test import TestCase class SimpleTest(TestCase): ''' Your unit tests go here ''' def test_a(self): pass def run(self, result=None): if result is None: result = self.defaultTestResult() try: super(SimpleTest, self).run(result) except KeyboardInterrupt: result.stop()
More like this
- Serializer factory with Django Rest Framework by julio 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 6 months, 2 weeks ago
- Help text hyperlinks by sa2812 7 months, 2 weeks ago
- Stuff by NixonDash 9 months, 3 weeks ago
- Add custom fields to the built-in Group model by jmoppel 11 months, 3 weeks ago