Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11615 -- Changed test runners to use an exit status code of 1 …

…for any number of failed tests. The previous behavior of using an exit status code equal to the number of failed tests produced incorrect exit status codes when the number of test failures was 256 or greater. Thanks to lamby for the report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12068 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 5dd6bbd2cfa413497333b482889cbe1b1f413658 1 parent a5fc65b
Gary Wilson Jr. authored January 03, 2010
6  django/core/management/commands/test.py
@@ -17,7 +17,7 @@ class Command(BaseCommand):
17 17
     def handle(self, *test_labels, **options):
18 18
         from django.conf import settings
19 19
         from django.test.utils import get_runner
20  
-        
  20
+
21 21
         verbosity = int(options.get('verbosity', 1))
22 22
         interactive = options.get('interactive', True)
23 23
         failfast = options.get('failfast', False)
@@ -25,10 +25,10 @@ def handle(self, *test_labels, **options):
25 25
 
26 26
         # Some custom test runners won't accept the failfast flag, so let's make sure they accept it before passing it to them
27 27
         if 'failfast' in test_runner.func_code.co_varnames:
28  
-            failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive, 
  28
+            failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive,
29 29
                                    failfast=failfast)
30 30
         else:
31 31
             failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive)
32 32
 
33 33
         if failures:
34  
-            sys.exit(failures)
  34
+            sys.exit(bool(failures))
20  docs/releases/1.2.txt
@@ -232,6 +232,16 @@ party packages, or that you wrote yourself, you should ensure that the
232 232
 information, see
233 233
 :ref:`template tag thread safety considerations<template_tag_thread_safety>`.
234 234
 
  235
+Test runner exit status code
  236
+----------------------------
  237
+
  238
+The exit status code of the test runners (``tests/runtests.py`` and ``python
  239
+manage.py test``) no longer represents the number of failed tests, since a
  240
+failure of 256 or more tests resulted in a wrong exit status code.  The exit
  241
+status code for the test runner is now 0 for success (no failing tests) and 1
  242
+for any number of test failures.  If needed, the number of test failures can be
  243
+found at the end of the test runner's output.
  244
+
235 245
 .. _deprecated-features-1.2:
236 246
 
237 247
 Features deprecated in 1.2
@@ -471,12 +481,12 @@ Models can now use a 64 bit :class:`~django.db.models.BigIntegerField` type.
471 481
 Fast Failure for Tests
472 482
 ----------------------
473 483
 
474  
-The :djadmin:`test` subcommand of ``django-admin.py``, and the ``runtests.py`` 
  484
+The :djadmin:`test` subcommand of ``django-admin.py``, and the ``runtests.py``
475 485
 script used to run Django's own test suite, support a new ``--failfast`` option.
476  
-When specified, this option causes the test runner to exit after encountering 
477  
-a failure instead of continuing with the test run.  In addition, the handling 
478  
-of ``Ctrl-C`` during a test run has been improved to trigger a graceful exit 
479  
-from the test run that reports details of the tests run before the interruption.        
  486
+When specified, this option causes the test runner to exit after encountering
  487
+a failure instead of continuing with the test run.  In addition, the handling
  488
+of ``Ctrl-C`` during a test run has been improved to trigger a graceful exit
  489
+from the test run that reports details of the tests run before the interruption.
480 490
 
481 491
 Improved localization
482 492
 ---------------------
2  tests/runtests.py
@@ -162,7 +162,7 @@ def django_tests(verbosity, interactive, failfast, test_labels):
162 162
     failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive, failfast=failfast,
163 163
                            extra_tests=extra_tests)
164 164
     if failures:
165  
-        sys.exit(failures)
  165
+        sys.exit(bool(failures))
166 166
 
167 167
     # Restore the old settings.
168 168
     settings.INSTALLED_APPS = old_installed_apps

0 notes on commit 5dd6bbd

Please sign in to comment.
Something went wrong with that request. Please try again.