MCPcopy
hub / github.com/django/django / set_available_apps

Method set_available_apps

django/apps/registry.py:306–332  ·  view source on GitHub ↗

Restrict the set of installed apps used by get_app_config[s]. available must be an iterable of application names. set_available_apps() must be balanced with unset_available_apps(). Primarily used for performance optimization in TransactionTestCase. This m

(self, available)

Source from the content-addressed store, hash-verified

304 return None
305
306 def set_available_apps(self, available):
307 """
308 Restrict the set of installed apps used by get_app_config[s].
309
310 available must be an iterable of application names.
311
312 set_available_apps() must be balanced with unset_available_apps().
313
314 Primarily used for performance optimization in TransactionTestCase.
315
316 This method is safe in the sense that it doesn't trigger any imports.
317 """
318 available = set(available)
319 installed = {app_config.name for app_config in self.get_app_configs()}
320 if not available.issubset(installed):
321 raise ValueError(
322 "Available apps isn't a subset of installed apps, extra apps: %s"
323 % ", ".join(available - installed)
324 )
325
326 self.stored_app_configs.append(self.app_configs)
327 self.app_configs = {
328 label: app_config
329 for label, app_config in self.app_configs.items()
330 if app_config.name in available
331 }
332 self.clear_cache()
333
334 def unset_available_apps(self):
335 """Cancel a previous call to set_available_apps()."""

Callers 2

_pre_setupMethod · 0.80
_fixture_setupMethod · 0.80

Calls 5

get_app_configsMethod · 0.95
clear_cacheMethod · 0.95
joinMethod · 0.45
appendMethod · 0.45
itemsMethod · 0.45

Tested by 2

_pre_setupMethod · 0.64
_fixture_setupMethod · 0.64