<s> from django . test import TestCase <EOL> from django . test . simple import build_test , reorder_suite , build_suite <EOL> from django . test . utils import setup_test_environment , teardown_test_environment <EOL> from django . test . testcases import connections_support_transactions <EOL> from django . db . models import get_app , get_apps <EOL> from django . conf import settings <EOL> try : <EOL> from django . utils import unittest <EOL> except ImportError : <EOL> import unittest <EOL> import os <EOL> def run_tests ( test_labels , verbosity = <NUM_LIT:1> , interactive = True , extra_tests = [ ] ) : <EOL> """<STR_LIT>""" <EOL> setup_test_environment ( ) <EOL> settings . DEBUG = False <EOL> suite = unittest . TestSuite ( ) <EOL> if test_labels : <EOL> for label in test_labels : <EOL> if '<STR_LIT:.>' in label : <EOL> suite . addTest ( build_test ( label ) ) <EOL> else : <EOL> app = get_app ( label ) <EOL> suite . addTest ( build_suite ( app ) ) <EOL> else : <EOL> for app in get_apps ( ) : <EOL> suite . addTest ( build_suite ( app ) ) <EOL> for test in extra_tests : <EOL> suite . addTest ( test ) <EOL> suite = reorder_suite ( suite , ( TestCase , ) ) <EOL> old_name = settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] <EOL> from django . db . backends import creation <EOL> from django . db import connection , DatabaseError <EOL> if settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] : <EOL> settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] = settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] <EOL> else : <EOL> settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] = creation . TEST_DATABASE_PREFIX + settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] <EOL> connection . settings_dict [ "<STR_LIT>" ] = settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] <EOL> try : <EOL> if settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> if not os . path . exists ( settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] ) : <EOL> raise DatabaseError <EOL> cursor = connection . cursor ( ) <EOL> except Exception : <EOL> settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] = old_name <EOL> connection . settings_dict [ "<STR_LIT>" ] = old_name <EOL> connection . creation . create_test_db ( verbosity , autoclobber = True ) <EOL> else : <EOL> connection . close ( ) <EOL> settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] = connections_support_transactions ( ) <EOL> result = unittest . TextTestRunner ( verbosity = verbosity ) . run ( suite ) <EOL> settings . DATABASES [ '<STR_LIT:default>' ] [ '<STR_LIT>' ] = old_name <EOL> connection . settings_dict [ "<STR_LIT>" ] = old_name <EOL> teardown_test_environment ( ) <EOL> return len ( result . failures ) + len ( result . errors ) </s>
