Ticket #3253: runtests.diff

File runtests.diff, 3.6 KB (added by mir@…, 17 years ago)

the patch

  • django/core/management.py

    a b def test(app_labels, verbosity=1):  
    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
  • django/test/simple.py

    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,  
    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   
    def run_tests(module_list, verbosity=1,  
    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)
     89 No newline at end of file
  • docs/testing.txt

    diff --git a/docs/testing.txt b/docs/testing.txt
    index a0b8a8a18724dd631db5c5613af98d328875ee2f..b2e8a46054eb242fb2b53f34503ece0e5ddab134 100644
    a b failed::  
    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
    #. Looking for Unit Tests and Doctests i  
    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
  • tests/runtests.py

    diff --git a/tests/runtests.py b/tests/runtests.py
    index 20189c2d995c5dca6dda893c56a5078a3ffe2909..bae4dc76262984b5cef87d5dca0f3073ee8f12fe 100755
    a b def django_tests(verbosity, tests_to_run  
    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
    def django_tests(verbosity, tests_to_run  
    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 ...]"
    if __name__ == "__main__":  
    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)
Back to Top