Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #3253 -- Exposed the number of failed tests as a return code in…

… manage.py and runtests.py.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@4608 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f313e07b6e0914130b613c3491b2b019ca003dc7 1 parent c27ba0b
Russell Keith-Magee authored February 26, 2007
5  django/core/management.py
@@ -1240,7 +1240,10 @@ def test(app_labels, verbosity=1):
1240 1240
     test_module = __import__(test_module_name, {}, {}, test_path[-1])
1241 1241
     test_runner = getattr(test_module, test_path[-1])
1242 1242
 
1243  
-    test_runner(app_list, verbosity)
  1243
+    failures = test_runner(app_list, verbosity)
  1244
+    if failures:
  1245
+        sys.exit(failures)
  1246
+        
1244 1247
 test.help_doc = 'Runs the test suite for the specified applications, or the entire site if no apps are specified'
1245 1248
 test.args = '[--verbosity] ' + APP_ARGS
1246 1249
 
7  django/test/simple.py
@@ -63,6 +63,8 @@ def run_tests(module_list, verbosity=1, extra_tests=[]):
63 63
     looking for doctests and unittests in models.py or tests.py within
64 64
     the module. A list of 'extra' tests may also be provided; these tests
65 65
     will be added to the test suite.
  66
+    
  67
+    Returns the number of tests that failed.
66 68
     """
67 69
     setup_test_environment()
68 70
     
@@ -77,7 +79,10 @@ def run_tests(module_list, verbosity=1, extra_tests=[]):
77 79
 
78 80
     old_name = settings.DATABASE_NAME
79 81
     create_test_db(verbosity)
80  
-    unittest.TextTestRunner(verbosity=verbosity).run(suite)
  82
+    result = unittest.TextTestRunner(verbosity=verbosity).run(suite)
81 83
     destroy_test_db(old_name, verbosity)
82 84
     
83 85
     teardown_test_environment()
  86
+    
  87
+    return len(result.failures)
  88
+    
12  docs/testing.txt
@@ -417,7 +417,10 @@ failed::
417 417
 
418 418
     FAILED (failures=1)
419 419
 
420  
-When the tests have all been executed, the test database is destroyed.
  420
+The return code for the script will indicate the number of tests that failed.
  421
+
  422
+Regardless of whether the tests pass or fail, the test database is destroyed when
  423
+all the tests have been executed. 
421 424
 
422 425
 Using a different testing framework
423 426
 ===================================
@@ -428,7 +431,8 @@ it does provide a mechanism to allow you to invoke tests constructed for
428 431
 an alternative framework as if they were normal Django tests.
429 432
 
430 433
 When you run ``./manage.py test``, Django looks at the ``TEST_RUNNER``
431  
-setting to determine what to do. By default, ``TEST_RUNNER`` points to ``django.test.simple.run_tests``. This method defines the default Django
  434
+setting to determine what to do. By default, ``TEST_RUNNER`` points to 
  435
+``django.test.simple.run_tests``. This method defines the default Django
432 436
 testing behavior. This behavior involves:
433 437
 
434 438
 #. Performing global pre-test setup
@@ -436,7 +440,7 @@ testing behavior. This behavior involves:
436 440
 #. Running ``syncdb`` to install models and initial data into the test database
437 441
 #. Looking for Unit Tests and Doctests in ``models.py`` and ``tests.py`` file for each installed application
438 442
 #. Running the Unit Tests and Doctests that are found
439  
-#. Destroying the test database.
  443
+#. Destroying the test database
440 444
 #. Performing global post-test teardown
441 445
 
442 446
 If you define your own test runner method and point ``TEST_RUNNER``
@@ -457,6 +461,8 @@ arguments:
457 461
     Verbosity determines the amount of notification and debug information that
458 462
     will be printed to the console; `0` is no output, `1` is normal output,
459 463
     and `2` is verbose output.
  464
+    
  465
+    This method should return the number of tests that failed.
460 466
 
461 467
 Testing utilities
462 468
 -----------------
4  tests/runtests.py
@@ -124,7 +124,9 @@ def django_tests(verbosity, tests_to_run):
124 124
 
125 125
     # Run the test suite, including the extra validation tests.
126 126
     from django.test.simple import run_tests
127  
-    run_tests(test_models, verbosity, extra_tests=extra_tests)
  127
+    failures = run_tests(test_models, verbosity, extra_tests=extra_tests)
  128
+    if failures:
  129
+        sys.exit(failures)
128 130
 
129 131
     # Restore the old settings.
130 132
     settings.INSTALLED_APPS = old_installed_apps

0 notes on commit f313e07

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