Django

Code

Ticket #3253: runtests.diff

File runtests.diff, 3.6 kB (added by mir@noris.de, 2 years ago)

the patch

  • a/django/core/management.py

    old new  
    12421242    test_module = __import__(test_module_name, {}, {}, test_path[-1]) 
    12431243    test_runner = getattr(test_module, test_path[-1]) 
    12441244 
    1245     test_runner(app_list, verbosity) 
     1245    failures = test_runner(app_list, verbosity) 
     1246    if failures: 
     1247        sys.exit(1) 
     1248    else: 
     1249        sys.exit(0) 
     1250         
    12461251test.help_doc = 'Runs the test suite for the specified applications, or the entire site if no apps are specified' 
    12471252test.args = '[--verbosity] ' + APP_ARGS 
    12481253 
  • a/django/test/simple.py

    old new  
    6464    looking for doctests and unittests in models.py or tests.py within 
    6565    the module. A list of 'extra' tests may also be provided; these tests 
    6666    will be added to the test suite. 
     67 
     68    Returns the number of failures. 
    6769    """ 
    6870    setup_test_environment() 
    6971     
     
    7981    old_name = settings.DATABASE_NAME 
    8082    create_test_db(verbosity) 
    8183    management.syncdb(verbosity, interactive=False) 
    82     unittest.TextTestRunner(verbosity=verbosity).run(suite) 
     84    test_result = unittest.TextTestRunner(verbosity=verbosity).run(suite) 
    8385    destroy_test_db(old_name, verbosity) 
    8486     
    8587    teardown_test_environment() 
     88    return len(test_result.failures) 
  • a/docs/testing.txt

    old new  
    379379 
    380380When the tests have all been executed, the test database is destroyed. 
    381381 
     382You can use the exit code of ``manage.py test`` for automation: it is 
     3830 in case of success, and 1 in case of any test failures. 
     384 
    382385Using a different testing framework 
    383386=================================== 
    384387 
     
    398401#. Running the Unit Tests and Doctests that are found 
    399402#. Destroying the test database. 
    400403#. Performing global post-test teardown 
     404#. Returning the number of failures 
    401405 
    402406If you define your own test runner method and point ``TEST_RUNNER`` 
    403407at that method, Django will execute your test runner whenever you run 
  • a/tests/runtests.py

    old new  
    118118 
    119119    # Run the test suite, including the extra validation tests. 
    120120    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) 
    122122 
    123123    # Restore the old settings 
    124124    settings.INSTALLED_APPS = old_installed_apps 
     
    127127    settings.TEMPLATE_DIRS = old_template_dirs 
    128128    settings.USE_I18N = old_use_i18n 
    129129 
     130    return failures 
     131 
    130132if __name__ == "__main__": 
    131133    from optparse import OptionParser 
    132134    usage = "%prog [options] [model model model ...]" 
     
    140142    if options.settings: 
    141143        os.environ['DJANGO_SETTINGS_MODULE'] = options.settings 
    142144 
    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)