Ticket #12991: t12991-rc2__unittest_catchbreak.diff

File t12991-rc2__unittest_catchbreak.diff, 7.4 KB (added by Łukasz Rekucki, 14 years ago)
  • django/test/simple.py

    diff --git a/django/test/simple.py b/django/test/simple.py
    index c0194b8..78e453c 100644
    a b TEST_MODULE = 'tests'  
    1414doctestOutputChecker = OutputChecker()
    1515
    1616class DjangoTestRunner(unittest.TextTestRunner):
    17 
    18     def __init__(self, verbosity=0, failfast=False, **kwargs):
    19         super(DjangoTestRunner, self).__init__(verbosity=verbosity, **kwargs)
    20         self.failfast = failfast
    21         self._keyboard_interrupt_intercepted = False
    22 
    23     def run(self, *args, **kwargs):
    24         """
    25         Runs the test suite after registering a custom signal handler
    26         that triggers a graceful exit when Ctrl-C is pressed.
    27         """
    28         self._default_keyboard_interrupt_handler = signal.signal(signal.SIGINT,
    29             self._keyboard_interrupt_handler)
    30         try:
    31             result = super(DjangoTestRunner, self).run(*args, **kwargs)
    32         finally:
    33             signal.signal(signal.SIGINT, self._default_keyboard_interrupt_handler)
    34         return result
    35 
    36     def _keyboard_interrupt_handler(self, signal_number, stack_frame):
    37         """
    38         Handles Ctrl-C by setting a flag that will stop the test run when
    39         the currently running test completes.
    40         """
    41         self._keyboard_interrupt_intercepted = True
    42         sys.stderr.write(" <Test run halted by Ctrl-C> ")
    43         # Set the interrupt handler back to the default handler, so that
    44         # another Ctrl-C press will trigger immediate exit.
    45         signal.signal(signal.SIGINT, self._default_keyboard_interrupt_handler)
    46 
    47     def _makeResult(self):
    48         result = super(DjangoTestRunner, self)._makeResult()
    49         failfast = self.failfast
    50 
    51         def stoptest_override(func):
    52             def stoptest(test):
    53                 # If we were set to failfast and the unit test failed,
    54                 # or if the user has typed Ctrl-C, report and quit
    55                 if (failfast and not result.wasSuccessful()) or \
    56                     self._keyboard_interrupt_intercepted:
    57                     result.stop()
    58                 func(test)
    59             return stoptest
    60 
    61         result.stopTest = stoptest_override(result.stopTest)
    62         return result
     17    pass
    6318
    6419def get_tests(app_module):
    6520    try:
    class DjangoTestSuiteRunner(object):  
    232187    def setup_test_environment(self, **kwargs):
    233188        setup_test_environment()
    234189        settings.DEBUG = False
     190        unittest.installHandler()
    235191
    236192    def build_suite(self, test_labels, extra_tests=None, **kwargs):
    237193        suite = unittest.TestSuite()
    class DjangoTestSuiteRunner(object):  
    284240            connection.creation.destroy_test_db(old_name, self.verbosity)
    285241
    286242    def teardown_test_environment(self, **kwargs):
     243        unittest.removeHandler()
    287244        teardown_test_environment()
    288245
    289246    def suite_result(self, suite, result, **kwargs):
  • tests/regressiontests/admin_views/tests.py

    diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
    index 725369a..b856afc 100644
    a b from django.utils.cache import get_max_age  
    1818from django.utils.encoding import iri_to_uri
    1919from django.utils.html import escape
    2020from django.utils.translation import get_date_formats, activate, deactivate
     21from django.utils import unittest
    2122
    2223# local test models
    2324from models import Article, BarAccount, CustomArticle, EmptyModel, \
    class UserAdminTest(TestCase):  
    22092210        self.assertNotEquals(new_user.password, UNUSABLE_PASSWORD)
    22102211
    22112212try:
    2212     # If docutils isn't installed, skip the AdminDocs tests.
    22132213    import docutils
     2214except ImportError:
     2215    docutils = None
    22142216
    2215     class AdminDocsTest(TestCase):
    2216         fixtures = ['admin-views-users.xml']
     2217#@unittest.skipUnless(docutils, "no docutils installed.")
     2218class AdminDocsTest(TestCase):
     2219    fixtures = ['admin-views-users.xml']
    22172220
    2218         def setUp(self):
    2219             self.client.login(username='super', password='secret')
     2221    def setUp(self):
     2222        self.client.login(username='super', password='secret')
    22202223
    2221         def tearDown(self):
    2222             self.client.logout()
     2224    def tearDown(self):
     2225        self.client.logout()
    22232226
    2224         def test_tags(self):
    2225             response = self.client.get('/test_admin/admin/doc/tags/')
     2227    def test_tags(self):
     2228        response = self.client.get('/test_admin/admin/doc/tags/')
    22262229
    2227             # The builtin tag group exists
    2228             self.assertContains(response, "<h2>Built-in tags</h2>", count=2)
     2230        # The builtin tag group exists
     2231        self.assertContains(response, "<h2>Built-in tags</h2>", count=2)
    22292232
    2230             # A builtin tag exists in both the index and detail
    2231             self.assertContains(response, '<h3 id="built_in-autoescape">autoescape</h3>')
    2232             self.assertContains(response, '<li><a href="#built_in-autoescape">autoescape</a></li>')
     2233        # A builtin tag exists in both the index and detail
     2234        self.assertContains(response, '<h3 id="built_in-autoescape">autoescape</h3>')
     2235        self.assertContains(response, '<li><a href="#built_in-autoescape">autoescape</a></li>')
    22332236
    2234             # An app tag exists in both the index and detail
    2235             self.assertContains(response, '<h3 id="flatpages-get_flatpages">get_flatpages</h3>')
    2236             self.assertContains(response, '<li><a href="#flatpages-get_flatpages">get_flatpages</a></li>')
     2237        # An app tag exists in both the index and detail
     2238        self.assertContains(response, '<h3 id="flatpages-get_flatpages">get_flatpages</h3>')
     2239        self.assertContains(response, '<li><a href="#flatpages-get_flatpages">get_flatpages</a></li>')
    22372240
    2238             # The admin list tag group exists
    2239             self.assertContains(response, "<h2>admin_list</h2>", count=2)
     2241        # The admin list tag group exists
     2242        self.assertContains(response, "<h2>admin_list</h2>", count=2)
    22402243
    2241             # An admin list tag exists in both the index and detail
    2242             self.assertContains(response, '<h3 id="admin_list-admin_actions">admin_actions</h3>')
    2243             self.assertContains(response, '<li><a href="#admin_list-admin_actions">admin_actions</a></li>')
     2244        # An admin list tag exists in both the index and detail
     2245        self.assertContains(response, '<h3 id="admin_list-admin_actions">admin_actions</h3>')
     2246        self.assertContains(response, '<li><a href="#admin_list-admin_actions">admin_actions</a></li>')
    22442247
    2245         def test_filters(self):
    2246             response = self.client.get('/test_admin/admin/doc/filters/')
     2248    def test_filters(self):
     2249        response = self.client.get('/test_admin/admin/doc/filters/')
    22472250
    2248             # The builtin filter group exists
    2249             self.assertContains(response, "<h2>Built-in filters</h2>", count=2)
     2251        # The builtin filter group exists
     2252        self.assertContains(response, "<h2>Built-in filters</h2>", count=2)
    22502253
    2251             # A builtin filter exists in both the index and detail
    2252             self.assertContains(response, '<h3 id="built_in-add">add</h3>')
    2253             self.assertContains(response, '<li><a href="#built_in-add">add</a></li>')
     2254        # A builtin filter exists in both the index and detail
     2255        self.assertContains(response, '<h3 id="built_in-add">add</h3>')
     2256        self.assertContains(response, '<li><a href="#built_in-add">add</a></li>')
    22542257
    2255 except ImportError:
    2256     pass
     2258AdminDocsTest = unittest.skipUnless(docutils, "no docutils installed.")(AdminDocsTest)
     2259 No newline at end of file
Back to Top