diff --git a/django/test/simple.py b/django/test/simple.py
index 88e6b49925605d9cd141c77f328b99e8012bab1b..7c0bd9dd8a0124accfd797a195914cf3f586d285 100644
a
|
b
|
def run_tests(module_list, verbosity=1,
|
64 | 64 | looking for doctests and unittests in models.py or tests.py within |
65 | 65 | the module. A list of 'extra' tests may also be provided; these tests |
66 | 66 | will be added to the test suite. |
| 67 | |
| 68 | Returns the number of failures. |
67 | 69 | """ |
68 | 70 | setup_test_environment() |
69 | 71 | |
… |
… |
def run_tests(module_list, verbosity=1,
|
79 | 81 | old_name = settings.DATABASE_NAME |
80 | 82 | create_test_db(verbosity) |
81 | 83 | management.syncdb(verbosity, interactive=False) |
82 | | unittest.TextTestRunner(verbosity=verbosity).run(suite) |
| 84 | test_result = unittest.TextTestRunner(verbosity=verbosity).run(suite) |
83 | 85 | destroy_test_db(old_name, verbosity) |
84 | 86 | |
85 | 87 | teardown_test_environment() |
| 88 | return len(test_result.failures) |
| 89 | No newline at end of file |
diff --git a/docs/testing.txt b/docs/testing.txt
index a0b8a8a18724dd631db5c5613af98d328875ee2f..b2e8a46054eb242fb2b53f34503ece0e5ddab134 100644
a
|
b
|
failed::
|
379 | 379 | |
380 | 380 | When the tests have all been executed, the test database is destroyed. |
381 | 381 | |
| 382 | You can use the exit code of ``manage.py test`` for automation: it is |
| 383 | 0 in case of success, and 1 in case of any test failures. |
| 384 | |
382 | 385 | Using a different testing framework |
383 | 386 | =================================== |
384 | 387 | |
… |
… |
#. Looking for Unit Tests and Doctests i
|
398 | 401 | #. Running the Unit Tests and Doctests that are found |
399 | 402 | #. Destroying the test database. |
400 | 403 | #. Performing global post-test teardown |
| 404 | #. Returning the number of failures |
401 | 405 | |
402 | 406 | If you define your own test runner method and point ``TEST_RUNNER`` |
403 | 407 | at that method, Django will execute your test runner whenever you run |
diff --git a/tests/runtests.py b/tests/runtests.py
index 20189c2d995c5dca6dda893c56a5078a3ffe2909..bae4dc76262984b5cef87d5dca0f3073ee8f12fe 100755
a
|
b
|
def django_tests(verbosity, tests_to_run
|
118 | 118 | |
119 | 119 | # Run the test suite, including the extra validation tests. |
120 | 120 | from django.test.simple import run_tests |
121 | | run_tests(test_models, verbosity, extra_tests=extra_tests) |
| 121 | failures = run_tests(test_models, verbosity, extra_tests=extra_tests) |
122 | 122 | |
123 | 123 | # Restore the old settings |
124 | 124 | settings.INSTALLED_APPS = old_installed_apps |
… |
… |
def django_tests(verbosity, tests_to_run
|
127 | 127 | settings.TEMPLATE_DIRS = old_template_dirs |
128 | 128 | settings.USE_I18N = old_use_i18n |
129 | 129 | |
| 130 | return failures |
| 131 | |
130 | 132 | if __name__ == "__main__": |
131 | 133 | from optparse import OptionParser |
132 | 134 | usage = "%prog [options] [model model model ...]" |
… |
… |
if __name__ == "__main__":
|
140 | 142 | if options.settings: |
141 | 143 | os.environ['DJANGO_SETTINGS_MODULE'] = options.settings |
142 | 144 | |
143 | | django_tests(int(options.verbosity), args) |
| 145 | failures = django_tests(int(options.verbosity), args) |
| 146 | if failures: |
| 147 | sys.exit(1) |
| 148 | else: |
| 149 | sys.exit(0) |