- May 22, 2007
- 0 (after 0 ratings)
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
- Super User Conditional Page Exception Reporting by zbyte64 8 years, 1 month ago
- Variable._resolve_lookup monkeypatch by showell 6 years, 9 months ago
- Capture Stack Trace Decorator by LorenDavie 6 years, 3 months ago
- A smart trace() command by aparajita 7 years, 2 months ago
- Stop tests at the first failure by akaihola 8 years, 8 months ago