Ticket #12991: t12991-rc2__unittest_catchbreak.diff
File t12991-rc2__unittest_catchbreak.diff, 7.4 KB (added by , 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' 14 14 doctestOutputChecker = OutputChecker() 15 15 16 16 class 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 63 18 64 19 def get_tests(app_module): 65 20 try: … … class DjangoTestSuiteRunner(object): 232 187 def setup_test_environment(self, **kwargs): 233 188 setup_test_environment() 234 189 settings.DEBUG = False 190 unittest.installHandler() 235 191 236 192 def build_suite(self, test_labels, extra_tests=None, **kwargs): 237 193 suite = unittest.TestSuite() … … class DjangoTestSuiteRunner(object): 284 240 connection.creation.destroy_test_db(old_name, self.verbosity) 285 241 286 242 def teardown_test_environment(self, **kwargs): 243 unittest.removeHandler() 287 244 teardown_test_environment() 288 245 289 246 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 18 18 from django.utils.encoding import iri_to_uri 19 19 from django.utils.html import escape 20 20 from django.utils.translation import get_date_formats, activate, deactivate 21 from django.utils import unittest 21 22 22 23 # local test models 23 24 from models import Article, BarAccount, CustomArticle, EmptyModel, \ … … class UserAdminTest(TestCase): 2209 2210 self.assertNotEquals(new_user.password, UNUSABLE_PASSWORD) 2210 2211 2211 2212 try: 2212 # If docutils isn't installed, skip the AdminDocs tests.2213 2213 import docutils 2214 except ImportError: 2215 docutils = None 2214 2216 2215 class AdminDocsTest(TestCase): 2216 fixtures = ['admin-views-users.xml'] 2217 #@unittest.skipUnless(docutils, "no docutils installed.") 2218 class AdminDocsTest(TestCase): 2219 fixtures = ['admin-views-users.xml'] 2217 2220 2218 2219 2221 def setUp(self): 2222 self.client.login(username='super', password='secret') 2220 2223 2221 2222 2224 def tearDown(self): 2225 self.client.logout() 2223 2226 2224 2225 2227 def test_tags(self): 2228 response = self.client.get('/test_admin/admin/doc/tags/') 2226 2229 2227 2228 2230 # The builtin tag group exists 2231 self.assertContains(response, "<h2>Built-in tags</h2>", count=2) 2229 2232 2230 2231 2232 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>') 2233 2236 2234 2235 2236 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>') 2237 2240 2238 2239 2241 # The admin list tag group exists 2242 self.assertContains(response, "<h2>admin_list</h2>", count=2) 2240 2243 2241 2242 2243 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>') 2244 2247 2245 2246 2248 def test_filters(self): 2249 response = self.client.get('/test_admin/admin/doc/filters/') 2247 2250 2248 2249 2251 # The builtin filter group exists 2252 self.assertContains(response, "<h2>Built-in filters</h2>", count=2) 2250 2253 2251 2252 2253 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>') 2254 2257 2255 except ImportError: 2256 pass2258 AdminDocsTest = unittest.skipUnless(docutils, "no docutils installed.")(AdminDocsTest) 2259 No newline at end of file