def begin(self):
for plugin in self.nose_config.plugins.plugins:<EOL><INDENT>if getattr(plugin, '<STR_LIT>', False):<EOL><INDENT>self.django_plugins.append(plugin)<EOL><DEDENT><DEDENT>os.environ['<STR_LIT>'] = self.settings_module<EOL>if self.conf.addPaths:<EOL><INDENT>map(add_path, self.conf.where)<EOL><DEDENT>try:<EOL><INDENT>__import__(self.settings_module)<EOL>self.settings_path = self.settings_module<EOL><DEDENT>except ImportError:<EOL><INDENT>self.settings_path = get_settings_path(self.settings_module)<EOL>if not self.settings_path:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>add_path(self.settings_path)<EOL>sys.path.append(self.settings_path)<EOL><DEDENT>from django.conf import settings<EOL>settings.DEBUG = False<EOL>self.call_plugins_method('<STR_LIT>', settings)<EOL>from django.core import management<EOL>from django.test.utils import setup_test_environment<EOL>if hasattr(settings, '<STR_LIT>'):<EOL><INDENT>self.old_db = settings.DATABASES['<STR_LIT:default>']['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>self.old_db = settings.DATABASE_NAME<EOL><DEDENT>from django.db import connections<EOL>self._monkeypatch_test_classes()<EOL>for connection in connections.all():<EOL><INDENT>self.call_plugins_method(<EOL>'<STR_LIT>', settings, setup_test_environment,<EOL>connection)<EOL><DEDENT>try:<EOL><INDENT>setup_test_environment()<EOL><DEDENT>except RuntimeError:  <EOL><INDENT>pass<EOL><DEDENT>import django<EOL>if hasattr(django, '<STR_LIT>'):<EOL><INDENT>django.setup()<EOL><DEDENT>self.call_plugins_method('<STR_LIT>', settings)<EOL>management.get_commands()<EOL>if self.django_version < self.DJANGO_1_7:<EOL><INDENT>management._commands['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>for connection in connections.all():<EOL><INDENT>self.call_plugins_method(<EOL>'<STR_LIT>', settings, connection, management)<EOL>connection.creation.create_test_db(<EOL>verbosity=self.verbosity,<EOL>autoclobber=True,<EOL>)<EOL>logger.debug("<STR_LIT>")<EOL>self._num_syncdb_calls += <NUM_LIT:1><EOL>self.call_plugins_method('<STR_LIT>', settings, connection)<EOL><DEDENT>self.store_original_transaction_methods()<EOL>
Create the test database and schema, if needed, and switch the
connection over to that database. Then call install() to install
all apps listed in the loaded settings module.