Django

Code

Changeset 4608

Show
Ignore:
Timestamp:
02/26/07 06:52:01 (1 year ago)
Author:
russellm
Message:

Fixed #3253 -- Exposed the number of failed tests as a return code in manage.py and runtests.py.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/management.py

    r4533 r4608  
    12411241    test_runner = getattr(test_module, test_path[-1]) 
    12421242 
    1243     test_runner(app_list, verbosity) 
     1243    failures = test_runner(app_list, verbosity) 
     1244    if failures: 
     1245        sys.exit(failures) 
     1246         
    12441247test.help_doc = 'Runs the test suite for the specified applications, or the entire site if no apps are specified' 
    12451248test.args = '[--verbosity] ' + APP_ARGS 
  • django/trunk/django/test/simple.py

    r4541 r4608  
    6464    the module. A list of 'extra' tests may also be provided; these tests 
    6565    will be added to the test suite. 
     66     
     67    Returns the number of tests that failed. 
    6668    """ 
    6769    setup_test_environment() 
     
    7880    old_name = settings.DATABASE_NAME 
    7981    create_test_db(verbosity) 
    80     unittest.TextTestRunner(verbosity=verbosity).run(suite) 
     82    result = unittest.TextTestRunner(verbosity=verbosity).run(suite) 
    8183    destroy_test_db(old_name, verbosity) 
    8284     
    8385    teardown_test_environment() 
     86     
     87    return len(result.failures) 
     88     
  • django/trunk/docs/testing.txt

    r4529 r4608  
    418418    FAILED (failures=1) 
    419419 
    420 When the tests have all been executed, the test database is destroyed. 
     420The return code for the script will indicate the number of tests that failed. 
     421 
     422Regardless of whether the tests pass or fail, the test database is destroyed when 
     423all the tests have been executed.  
    421424 
    422425Using a different testing framework 
     
    429432 
    430433When 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 
     434setting to determine what to do. By default, ``TEST_RUNNER`` points to  
     435``django.test.simple.run_tests``. This method defines the default Django 
    432436testing behavior. This behavior involves: 
    433437 
     
    437441#. Looking for Unit Tests and Doctests in ``models.py`` and ``tests.py`` file for each installed application 
    438442#. Running the Unit Tests and Doctests that are found 
    439 #. Destroying the test database. 
     443#. Destroying the test database 
    440444#. Performing global post-test teardown 
    441445 
     
    458462    will be printed to the console; `0` is no output, `1` is normal output, 
    459463    and `2` is verbose output. 
     464     
     465    This method should return the number of tests that failed. 
    460466 
    461467Testing utilities 
  • django/trunk/tests/runtests.py

    r4473 r4608  
    125125    # Run the test suite, including the extra validation tests. 
    126126    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) 
    128130 
    129131    # Restore the old settings.