def handle(self, **options): runner = simple.DjangoTestSuiteRunner(verbosity=0) err_msg = "Failed to migrate %s; see output for hints at missing dependencies:\n" hacks.patch_flush_during_test_db_creation() failures = 0 for app_name in settings.INSTALLED_APPS: app_label = app_name.split(".")[-1] if app_name == 'south': continue try: Migrations(app_name) except NoMigrations: continue app = loading.get_app(app_label) verbosity = int(options.get('verbosity', 1)) if verbosity >= 1: self.stderr.write("processing %s\n" % app_name) old_config = runner.setup_databases() try: call_command('migrate', app_label, noinput=True, verbosity=verbosity) for model in loading.get_models(app): dummy = model._default_manager.exists() except (KeyboardInterrupt, SystemExit): raise except Exception, e: failures += 1 if verbosity >= 1: self.stderr.write(err_msg % app_name) self.stderr.write("%s\n" % e) finally:
def handle(self, *test_labels, **options): # handle south migration in tests management.get_commands() if hasattr(settings, "SOUTH_TESTS_MIGRATE") and not settings.SOUTH_TESTS_MIGRATE: # point at the core syncdb command when creating tests # tests should always be up to date with the most recent model structure management._commands['syncdb'] = 'django.core' elif 'south' in settings.INSTALLED_APPS: try: from south.management.commands import MigrateAndSyncCommand management._commands['syncdb'] = MigrateAndSyncCommand() from south.hacks import hacks if hasattr(hacks, "patch_flush_during_test_db_creation"): hacks.patch_flush_during_test_db_creation() except ImportError: management._commands['syncdb'] = 'django.core' verbosity = int(options.get('verbosity', 1)) interactive = options.get('interactive', True) failfast = options.get('failfast', False) TestRunner = self.get_runner() if not inspect.ismethod(TestRunner): failures = TestRunner(test_labels, verbosity=verbosity, interactive=interactive, failfast=failfast, keepdb='--keepdb' in sys.argv) else: test_runner = TestRunner(verbosity=verbosity, interactive=interactive, failfast=failfast) failures = test_runner.run_tests(test_labels) if failures: sys.exit(bool(failures))
def handle(self, *test_labels, **options): # handle south migration in tests commands = management.get_commands() if hasattr(settings, "SOUTH_TESTS_MIGRATE") and not settings.SOUTH_TESTS_MIGRATE: # point at the core syncdb command when creating tests # tests should always be up to date with the most recent model structure commands['syncdb'] = 'django.core' elif 'south' in settings.INSTALLED_APPS: try: from south.management.commands import MigrateAndSyncCommand commands['syncdb'] = MigrateAndSyncCommand() from south.hacks import hacks if hasattr(hacks, "patch_flush_during_test_db_creation"): hacks.patch_flush_during_test_db_creation() except ImportError: commands['syncdb'] = 'django.core' verbosity = int(options.get('verbosity', 1)) interactive = options.get('interactive', True) failfast = options.get('failfast', False) TestRunner = self.get_runner() if not inspect.ismethod(TestRunner): our_options = {"verbosity" : int(verbosity), "interactive" : interactive, "failfast" : failfast} options.update(our_options) failures = TestRunner(test_labels, **options) else: test_runner = TestRunner(verbosity=verbosity, interactive=interactive, failfast=failfast) failures = test_runner.run_tests(test_labels) if failures: sys.exit(bool(failures))
def patch_for_test_db_setup(): # Load the commands cache management.get_commands() # Repoint to the correct version of syncdb if hasattr(settings, "SOUTH_TESTS_MIGRATE") and not settings.SOUTH_TESTS_MIGRATE: # point at the core syncdb command when creating tests # tests should always be up to date with the most recent model structure management._commands['syncdb'] = 'django.core' else: management._commands['syncdb'] = MigrateAndSyncCommand() # Avoid flushing data migrations. # http://code.djangoproject.com/ticket/14661 introduced change that flushed custom # sql during the test database creation (thus flushing the data migrations). # we patch flush to be no-op during create_test_db, but still allow flushing # after each test for non-transactional backends. hacks.patch_flush_during_test_db_creation()
def patch_for_test_db_setup(): # Load the commands cache management.get_commands() # Repoint to the correct version of syncdb if hasattr(settings, "SOUTH_TESTS_MIGRATE") and not settings.SOUTH_TESTS_MIGRATE: # point at the core syncdb command when creating tests # tests should always be up to date with the most recent model structure management._commands['syncdb'] = 'django.core' else: management._commands['syncdb'] = MigrateAndSyncCommand() # Avoid flushing data migrations. # http://code.djangoproject.com/ticket/14661 introduced change that flushed custom # sql during the test database creation (thus flushing the data migrations). # we patch flush to be no-op during create_test_db, but still allow flushing # after each test for non-transactional backends. hacks.patch_flush_during_test_db_creation()
def handle(self, check_app_name=None, **options): runner = simple.DjangoTestSuiteRunner(verbosity=0) err_msg = "Failed to migrate %s; see output for hints at missing dependencies:\n" hacks.patch_flush_during_test_db_creation() failures = 0 if check_app_name is None: app_names = settings.INSTALLED_APPS else: app_names = [check_app_name] for app_name in app_names: app_label = app_name.split(".")[-1] if app_name == 'south': continue try: Migrations(app_name) except (NoMigrations, ImproperlyConfigured): continue app = loading.get_app(app_label) verbosity = int(options.get('verbosity', 1)) if verbosity >= 1: self.stderr.write("processing %s\n" % app_name) old_config = runner.setup_databases() try: call_command('migrate', app_label, noinput=True, verbosity=verbosity) for model in loading.get_models(app): dummy = model._default_manager.exists() except (KeyboardInterrupt, SystemExit): raise except Exception as e: failures += 1 if verbosity >= 1: self.stderr.write(err_msg % app_name) self.stderr.write("%s\n" % e) finally: runner.teardown_databases(old_config) if failures > 0: raise CommandError("Missing depends_on found in %s app(s)." % failures) self.stderr.write("No missing depends_on found.\n")
def enable_south_migrations(): #this was taken directly from the pycharm test runner management.get_commands() if hasattr(settings, "SOUTH_TESTS_MIGRATE") and not settings.SOUTH_TESTS_MIGRATE: # point at the core syncdb command when creating tests # tests should always be up to date with the most recent model structure management._commands['syncdb'] = 'django.core' elif 'south' in settings.INSTALLED_APPS: try: from south.management.commands import MigrateAndSyncCommand management._commands['syncdb'] = MigrateAndSyncCommand() from south.hacks import hacks if hasattr(hacks, "patch_flush_during_test_db_creation"): hacks.patch_flush_during_test_db_creation() except ImportError: management._commands['syncdb'] = 'django.core'
def enable_south_migrations(): #this was taken directly from the pycharm test runner management.get_commands() if hasattr(settings, "SOUTH_TESTS_MIGRATE") and not settings.SOUTH_TESTS_MIGRATE: # point at the core syncdb command when creating tests # tests should always be up to date with the most recent model structure management._commands['syncdb'] = 'django.core' elif 'south' in settings.INSTALLED_APPS: try: from south.management.commands import MigrateAndSyncCommand management._commands['syncdb'] = MigrateAndSyncCommand() from south.hacks import hacks if hasattr(hacks, "patch_flush_during_test_db_creation"): hacks.patch_flush_during_test_db_creation() except ImportError: management._commands['syncdb'] = 'django.core'
def handle(self, check_app_name=None, **options): runner = simple.DjangoTestSuiteRunner(verbosity=0) err_msg = "Failed to migrate %s; see output for hints at missing dependencies:\n" hacks.patch_flush_during_test_db_creation() failures = 0 if check_app_name is None: app_names = settings.INSTALLED_APPS else: app_names = [check_app_name] for app_name in app_names: app_label = app_name.split(".")[-1] if app_name == 'south': continue try: Migrations(app_name) except (NoMigrations, ImproperlyConfigured): continue app = loading.get_app(app_label) verbosity = int(options.get('verbosity', 1)) if verbosity >= 1: self.stderr.write("processing %s\n" % app_name) old_config = runner.setup_databases() try: call_command('migrate', app_label, noinput=True, verbosity=verbosity) for model in loading.get_models(app): dummy = model._default_manager.exists() except (KeyboardInterrupt, SystemExit): raise except Exception as e: failures += 1 if verbosity >= 1: self.stderr.write(err_msg % app_name) self.stderr.write("%s\n" % e) finally: runner.teardown_databases(old_config) if failures > 0: raise CommandError("Missing depends_on found in %s app(s)." % failures) self.stderr.write("No missing depends_on found.\n")
def begin(self): """ Initialize the test environment then create the test database and switch the connection over to that database. """ import django from django.conf import settings from django.db import connection from django.core import management from django.test.utils import setup_test_environment use_south = 'south' in settings.INSTALLED_APPS if use_south: from south import migration from south.hacks import hacks try: self.original_db_name = settings.DATABASE_NAME except AttributeError: # Django > 1.2 self.original_db_name = settings.DATABASES['default']['NAME'] try: django.setup() # Django >= 1.7 except AttributeError: pass setup_test_environment() if use_south: management.get_commands() hacks.patch_flush_during_test_db_creation() connection.creation.create_test_db(self.verbosity) if use_south: for app in migration.all_migrations(): migration.migrate_app(app, verbosity=self.verbosity)