def test_table_exists(self): try: app_cache.set_available_apps(settings.INSTALLED_APPS) call_command('migrate', verbosity=0) finally: app_cache.unset_available_apps() from .app1.models import ProxyModel from .app2.models import NiceModel self.assertEqual(NiceModel.objects.all().count(), 0) self.assertEqual(ProxyModel.objects.all().count(), 0)
def _pre_setup(self): """Performs any pre-test setup. This includes: * If the class has an 'available_apps' attribute, restricting the app cache to these applications, then firing post_migrate -- it must run with the correct set of applications for the test case. * If the class has a 'fixtures' attribute, installing these fixtures. """ super(TransactionTestCase, self)._pre_setup() if self.available_apps is not None: app_cache.set_available_apps(self.available_apps) for db_name in self._databases_names(include_mirrors=False): flush.Command.emit_post_migrate(verbosity=0, interactive=False, database=db_name) try: self._fixture_setup() except Exception: if self.available_apps is not None: app_cache.unset_available_apps() raise