def bisect_tests(bisection_label, options, test_labels):
    state = setup(int(options.verbosity), test_labels)

    if not test_labels:
        # Get the full list of test labels to use for bisection
        from django.db.models.loading import get_apps
        test_labels = [app.__name__.split('.')[-2] for app in get_apps()]

    print '***** Bisecting test suite:',' '.join(test_labels)

    # Make sure the bisection point isn't in the test list
    # Also remove tests that need to be run in specific combinations
    for label in [bisection_label, 'model_inheritance_same_model_name']:
        try:
            test_labels.remove(label)
        except __HOLE__:
            pass

    subprocess_args = ['python','runtests.py', '--settings=%s' % options.settings]
    if options.failfast:
        subprocess_args.append('--failfast')
    if options.verbosity:
        subprocess_args.append('--verbosity=%s' % options.verbosity)
    if not options.interactive:
        subprocess_args.append('--noinput')

    iteration = 1
    while len(test_labels) > 1:
        midpoint = len(test_labels)/2
        test_labels_a = test_labels[:midpoint] + [bisection_label]
        test_labels_b = test_labels[midpoint:] + [bisection_label]
        print '***** Pass %da: Running the first half of the test suite' % iteration
        print '***** Test labels:',' '.join(test_labels_a)
        failures_a = subprocess.call(subprocess_args + test_labels_a)

        print '***** Pass %db: Running the second half of the test suite' % iteration
        print '***** Test labels:',' '.join(test_labels_b)
        print
        failures_b = subprocess.call(subprocess_args + test_labels_b)

        if failures_a and not failures_b:
            print "***** Problem found in first half. Bisecting again..."
            iteration = iteration + 1
            test_labels = test_labels_a[:-1]
        elif failures_b and not failures_a:
            print "***** Problem found in second half. Bisecting again..."
            iteration = iteration + 1
            test_labels = test_labels_b[:-1]
        elif failures_a and failures_b:
            print "***** Multiple sources of failure found"
            break
        else:
            print "***** No source of failure found... try pair execution (--pair)"
            break

    if len(test_labels) == 1:
        print "***** Source of error:",test_labels[0]
    teardown(state)
dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-1.2/tests/runtests.py/bisect_tests