Django

Code

Changeset 5752

Show
Ignore:
Timestamp:
07/23/07 07:14:32 (1 year ago)
Author:
russellm
Message:

Fixed #3771 -- Modified the test runner to observe the --noinput argument controlling script interactivity. This means that test scripts can now be put in a buildbot environment. This is a backwards incompatible change for anyone that has written a custom test runner. Thanks for the suggestion, moof@metamoof.net.

Files:

Legend:

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

    r5738 r5752  
    13321332runfcgi.args = '[various KEY=val options, use `runfcgi help` for help]' 
    13331333 
    1334 def test(app_labels, verbosity=1): 
     1334def test(app_labels, verbosity=1, interactive=True): 
    13351335    "Runs the test suite for the specified applications" 
    13361336    from django.conf import settings 
     
    13511351    test_runner = getattr(test_module, test_path[-1]) 
    13521352 
    1353     failures = test_runner(app_list, verbosity
     1353    failures = test_runner(app_list, verbosity=verbosity, interactive=interactive
    13541354    if failures: 
    13551355        sys.exit(failures) 
    13561356 
    13571357test.help_doc = 'Runs the test suite for the specified applications, or the entire site if no apps are specified' 
    1358 test.args = '[--verbosity] ' + APP_ARGS 
     1358test.args = '[--verbosity] [--noinput]' + APP_ARGS 
    13591359 
    13601360def load_data(fixture_labels, verbosity=1): 
     
    16321632        except IndexError: 
    16331633            parser.print_usage_and_exit() 
    1634     elif action in ('test', 'loaddata'): 
     1634    elif action == 'test': 
     1635        try: 
     1636            action_mapping[action](args[1:], int(options.verbosity), options.interactive) 
     1637        except IndexError: 
     1638            parser.print_usage_and_exit() 
     1639    elif action == 'loaddata': 
    16351640        try: 
    16361641            action_mapping[action](args[1:], int(options.verbosity)) 
  • django/trunk/django/test/simple.py

    r5729 r5752  
    7070    return suite 
    7171 
    72 def run_tests(module_list, verbosity=1, extra_tests=[]): 
     72def run_tests(module_list, verbosity=1, interactive=True, extra_tests=[]): 
    7373    """ 
    7474    Run the unit tests for all the modules in the provided list. 
     
    9292 
    9393    old_name = settings.DATABASE_NAME 
    94     create_test_db(verbosity
     94    create_test_db(verbosity, autoclobber=not interactive
    9595    result = unittest.TextTestRunner(verbosity=verbosity).run(suite) 
    9696    destroy_test_db(old_name, verbosity) 
  • django/trunk/docs/testing.txt

    r5731 r5752  
    663663---------------------- 
    664664By convention, a test runner should be called ``run_tests``; however, you 
    665 can call it anything you want. The only requirement is that it accept two 
     665can call it anything you want. The only requirement is that it accept three 
    666666arguments: 
    667667 
    668 ``run_tests(module_list, verbosity=1)`` 
     668``run_tests(module_list, verbosity=1, interactive=True)`` 
    669669    The module list is the list of Python modules that contain the models to be 
    670670    tested. This is the same format returned by ``django.db.models.get_apps()`` 
     
    674674    and ``2`` is verbose output. 
    675675 
     676    **New in Django development version** If ``interactive`` is ``True``, the 
     677    test suite may ask the user for instructions when the test suite is 
     678    executed. An example of this behavior would be asking for permission to 
     679    delete an existing test database. If ``interactive`` is ``False, the  
     680    test suite must be able to run without any manual intervention. 
     681     
    676682    This method should return the number of tests that failed. 
    677683 
  • django/trunk/tests/runtests.py

    r5296 r5752  
    7474        self.assert_(not missing, "Missing Errors: " + '\n'.join(missing)) 
    7575 
    76 def django_tests(verbosity, tests_to_run): 
     76def django_tests(verbosity, interactive, tests_to_run): 
    7777    from django.conf import settings 
    7878 
     
    131131    # Run the test suite, including the extra validation tests. 
    132132    from django.test.simple import run_tests 
    133     failures = run_tests(test_models, verbosity, extra_tests=extra_tests) 
     133    failures = run_tests(test_models, verbosity=verbosity, interactive=interactive, extra_tests=extra_tests) 
    134134    if failures: 
    135135        sys.exit(failures) 
     
    150150        type='choice', choices=['0', '1', '2'], 
    151151        help='Verbosity level; 0=minimal output, 1=normal output, 2=all output') 
     152    parser.add_option('--noinput', action='store_false', dest='interactive', default=True, 
     153        help='Tells Django to NOT prompt the user for input of any kind.') 
    152154    parser.add_option('--settings', 
    153155        help='Python path to settings module, e.g. "myproject.settings". If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.') 
     
    158160        parser.error("DJANGO_SETTINGS_MODULE is not set in the environment. " 
    159161                      "Set it or use --settings.") 
    160     django_tests(int(options.verbosity), args) 
     162    django_tests(int(options.verbosity), options.interactive, args)