Ticket #12373: keepdb.diff

File keepdb.diff, 2.5 KB (added by Phui Hock, 14 years ago)
  • django/test/simple.py

     
    101101            raise ValueError("Test label '%s' does not refer to a test class" % label)
    102102        return TestClass(parts[2])
    103103
    104 def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):
     104def run_tests(test_labels, verbosity=1, interactive=True, keepdb=False, extra_tests=[]):
    105105    """
    106106    Run the unit tests for all the test labels in the provided list.
    107107    Labels must be of the form:
     
    143143    from django.db import connection
    144144    connection.creation.create_test_db(verbosity, autoclobber=not interactive)
    145145    result = unittest.TextTestRunner(verbosity=verbosity).run(suite)
    146     connection.creation.destroy_test_db(old_name, verbosity)
     146    if not keepdb:
     147        connection.creation.destroy_test_db(old_name, verbosity)
    147148
    148149    teardown_test_environment()
    149150
  • django/core/management/commands/test.py

     
    99            help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'),
    1010        make_option('--noinput', action='store_false', dest='interactive', default=True,
    1111            help='Tells Django to NOT prompt the user for input of any kind.'),
     12        make_option('--keepdb', action='store_true', dest='keepdb', default=False,
     13            help='Do not destroy test db at the end of tests.'),
    1214    )
    1315    help = 'Runs the test suite for the specified applications, or the entire site if no apps are specified.'
    1416    args = '[appname ...]'
     
    2022
    2123        verbosity = int(options.get('verbosity', 1))
    2224        interactive = options.get('interactive', True)
     25        keepdb = options.get('keepdb', False)
    2326   
    2427        test_path = settings.TEST_RUNNER.split('.')
    2528        # Allow for Python 2.5 relative paths
     
    2932            test_module_name = '.'
    3033        test_module = __import__(test_module_name, {}, {}, test_path[-1])
    3134        test_runner = getattr(test_module, test_path[-1])
    32 
    33         failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive)
     35        failures = test_runner(test_labels, verbosity=verbosity, interactive=interactive, keepdb=keepdb)
    3436        if failures:
    3537            sys.exit(failures)
Back to Top