Ticket #12364: ticket_12364.patch
File ticket_12364.patch, 3.1 KB (added by , 15 years ago) |
---|
-
django/test/simple.py
1 import signal 1 2 import unittest 3 2 4 from django.conf import settings 3 5 from django.db.models import get_app, get_apps 4 6 from django.test import _doctest as doctest … … 15 17 def __init__(self, verbosity=0, failfast=False, **kwargs): 16 18 super(DjangoTestRunner, self).__init__(verbosity=verbosity, **kwargs) 17 19 self.failfast = failfast 20 # We'll assume that the user hasn't yet typed CTRL-C :) 21 self._keyboard_interrupt_intercepted = False 22 23 def run(self, *args, **kwargs): 24 """ 25 We override the run method, for the purposes of registering our custom signal handler for the KEYBOARD INTERRUPT. 26 """ 27 # Let's remember the old keyboard interrupt, so we can replace it after run 28 self._default_keyboard_interrupt_handler = signal.signal(signal.SIGINT, self._keyboard_interrupt_handler) 29 result = super(DjangoTestRunner, self).run(*args, **kwargs) 30 # Replace the keyboard interrupt handler 31 signal.signal(signal.SIGINT, self._default_keyboard_interrupt_handler) 32 return result 33 34 def _keyboard_interrupt_handler(self, signal_number, stack_frame): 35 """ 36 This method will be called when a user types CTRL-C, once it is registered as a handler for CTRL-C. 37 """ 38 self._keyboard_interrupt_intercepted = True 39 # Let's set the interrupt handler back to the default handler, so that if the user presses CTRL-C again, they can kill the test 40 # suite. 41 signal.signal(signal.SIGINT, self._default_keyboard_interrupt_handler) 18 42 19 43 def _makeResult(self): 20 44 result = super(DjangoTestRunner, self)._makeResult() … … 22 46 23 47 def stoptest_override(func): 24 48 def stoptest(test): 25 if failfast and not result.wasSuccessful(): 49 # If we were set to failfast and the unit test failed, or if the user has typed CTRL-C, let's report and quit 50 if (failfast and not result.wasSuccessful()) or self._keyboard_interrupt_intercepted: 26 51 result.stop() 27 52 func(test) 28 53 return stoptest -
docs/ref/django-admin.txt
694 694 .. django-admin:: test 695 695 696 696 Runs tests for all installed models. See :ref:`topics-testing` for more 697 information. 697 information. If you send a keyboard interrupt (CTRL-C) to the running test 698 suite, the currently running unit test will complete, and the test suite will 699 then halt, reporting to you any errors you've come across so far. This is very 700 useful if you have forgotten to pass the --failfast flag. If you don't wish to 701 wait for the current unit test to complete for whatever reason, you can send an 702 additional keyboard interrupt to stop it immediately. 698 703 699 704 --failfast 700 705 ~~~~~~~~~~