Perform pre-test setup: * If the class has an 'available_apps' attribute, restrict the app registry to these applications, then fire the post_migrate signal -- it must run with the correct set of applications for the test case. * If the class has a 'fixtu
(cls)
| 1144 | |
| 1145 | @classmethod |
| 1146 | def _pre_setup(cls): |
| 1147 | """ |
| 1148 | Perform pre-test setup: |
| 1149 | * If the class has an 'available_apps' attribute, restrict the app |
| 1150 | registry to these applications, then fire the post_migrate signal -- |
| 1151 | it must run with the correct set of applications for the test case. |
| 1152 | * If the class has a 'fixtures' attribute, install those fixtures. |
| 1153 | """ |
| 1154 | super()._pre_setup() |
| 1155 | if cls.available_apps is not None: |
| 1156 | apps.set_available_apps(cls.available_apps) |
| 1157 | cls._available_apps_calls_balanced += 1 |
| 1158 | setting_changed.send( |
| 1159 | sender=settings._wrapped.__class__, |
| 1160 | setting="INSTALLED_APPS", |
| 1161 | value=cls.available_apps, |
| 1162 | enter=True, |
| 1163 | ) |
| 1164 | for db_name in cls._databases_names(include_mirrors=False): |
| 1165 | emit_post_migrate_signal(verbosity=0, interactive=False, db=db_name) |
| 1166 | try: |
| 1167 | cls._fixture_setup() |
| 1168 | except Exception: |
| 1169 | if cls.available_apps is not None: |
| 1170 | apps.unset_available_apps() |
| 1171 | setting_changed.send( |
| 1172 | sender=settings._wrapped.__class__, |
| 1173 | setting="INSTALLED_APPS", |
| 1174 | value=settings.INSTALLED_APPS, |
| 1175 | enter=False, |
| 1176 | ) |
| 1177 | raise |
| 1178 | # Clear the queries_log so that it's less likely to overflow (a single |
| 1179 | # test probably won't execute 9K queries). If queries_log overflows, |
| 1180 | # then assertNumQueries() doesn't work. |
| 1181 | for db_name in cls._databases_names(include_mirrors=False): |
| 1182 | connections[db_name].queries_log.clear() |
| 1183 | |
| 1184 | @classmethod |
| 1185 | def _databases_names(cls, include_mirrors=True): |
nothing calls this directly
no test coverage detected