Changeset 149 for trunk/test
- Timestamp:
- 12/31/07 13:14:18 (3 years ago)
- Files:
-
- 1 modified
-
trunk/test/simple.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/simple.py
r148 r149 1 __doc__ = """ 2 In your settings, use 3 4 TEST_RUNNER = 'ambidjangolib.test.simple.run_tests_until_fail' 5 6 to make `manage.py test` stop after the first test suite with failures, and 7 only show the first failing test in the suite. 8 """ 9 10 1 11 from unittest import \ 2 12 TestSuite, TextTestRunner, _TextTestResult, defaultTestLoader 3 from django.test ._doctest import DocTestSuite, REPORT_ONLY_FIRST_FAILURE13 from django.test import _doctest as doctest 4 14 from django.conf import settings 15 from django.db import transaction 5 16 from django.db.models import get_app, get_apps 6 from django.test.utils import setup_test_environment, teardown_test_environment 7 from django.test.utils import create_test_db, destroy_test_db 17 from django.test.utils import \ 18 setup_test_environment, teardown_test_environment, \ 19 create_test_db, destroy_test_db 8 20 from django.test.simple import build_test, get_tests, doctestOutputChecker 9 21 from django.test.testcases import DocTestRunner 10 22 11 23 24 class DocTestRunner(doctest.DocTestRunner): 25 """ 26 Replacement for django.test.testcases.DocTestRunner which unfortunately 27 overrides any supplied `optionflags=` kwarg with only `doctest.ELLIPSIS`. 28 We need to pass on optionflags. 29 """ 30 def __init__(self, *args, **kwargs): 31 doctest.DocTestRunner.__init__(self, *args, **kwargs) 32 self.optionflags |= doctest.ELLIPSIS 33 # Django's original has `=` instead of `|=` here 34 35 def report_unexpected_exception(self, out, test, example, exc_info): 36 doctest.DocTestRunner.report_unexpected_exception(self, out, test, 37 example, exc_info) 38 # Rollback, in case of database errors. Otherwise they'd have 39 # side effects on other tests. 40 transaction.rollback_unless_managed() 41 42 12 43 def _add_tests_for_module(suite, module): 44 """ 45 Repeated code from inside `build_suite()` is refactored here. 46 """ 13 47 # Load unit and doctests in the given module. If module has a suite() 14 48 # method, use it. Otherwise build the test suite ourselves. … … 18 52 suite.addTest(defaultTestLoader.loadTestsFromModule(module)) 19 53 try: 20 suite.addTest(DocTestSuite(module, 21 checker=doctestOutputChecker, 22 runner=DocTestRunner, 23 optionflags=REPORT_ONLY_FIRST_FAILURE)) 54 suite.addTest(doctest.DocTestSuite( 55 module, 56 checker=doctestOutputChecker, 57 runner=DocTestRunner, 58 optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) 24 59 except ValueError: 25 60 # No doc tests in models.py … … 28 63 29 64 def build_suite(app_module): 30 "Create a complete Django test suite for the provided application module" 65 """ 66 Create a complete Django test suite for the provided application module. 67 68 This overrides Django's original `django.test.simple.build_suite()` because 69 we need to pass the `REPORT_ONLY_FIRST_FAILURE` option flag to 70 `DocTestSuite` instances. 71 """ 31 72 suite = TestSuite() 32 73 33 74 _add_tests_for_module(suite, app_module) 34 75 35 # Check to see if a separate 'tests' module exists parallel to the 76 # Check to see if a separate 'tests' module exists parallel to the 36 77 # models module 37 78 test_module = get_tests(app_module) … … 77 118 Stops the tests at the first failure and returns 1. If all test pass, 78 119 returns 0. 120 121 Also displays only the first failure in the failing test suite. 79 122 """ 80 123 setup_test_environment()
