override_settings
Act as either a decorator or a context manager. If it's a decorator, take a function and return a wrapped function. If it's a contextmanager, use it with the with statement. In either event, entering/exiting are called before and after, respectively, the function/block is executed.
Attributes
| Attribute | Type | Description |
|---|---|---|
| enable_exception | Exception = null | Stores an exception captured during the setting change signal dispatch to be re-raised after the environment is restored. |
Constructor
Signature
def override_settings(
**kwargs: dict
)
Parameters
| Name | Type | Description |
|---|---|---|
| **kwargs | dict | Arbitrary keyword arguments representing the settings to be overridden. |
Signature
def override_settings(
**kwargs: dict
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| **kwargs | dict | Arbitrary keyword arguments where keys represent Django setting names and values represent the temporary values to apply. |
Methods
enable()
@classmethod
def enable() - > null
Activates the setting overrides by replacing the global settings object and broadcasting change signals for each modified key.
Returns
| Type | Description |
|---|---|
null |
disable()
@classmethod
def disable() - > null
Restores the original settings, unsets installed applications if necessary, and raises any exceptions encountered during the enable or disable phases.
Returns
| Type | Description |
|---|---|
null |
save_options()
@classmethod
def save_options(
test_func: callable|type
) - > null
Attaches the override configuration to the test function or class, merging with existing overrides if they are already present.
Parameters
| Name | Type | Description |
|---|---|---|
| test_func | `callable | type` |
Returns
| Type | Description |
|---|---|
null |
decorate_class()
@classmethod
def decorate_class(
cls: type
) - > type
Applies the setting overrides to a class, ensuring the class is a valid Django SimpleTestCase subclass before saving options.
Parameters
| Name | Type | Description |
|---|---|---|
| cls | type | The class to be decorated; must be a subclass of Django's SimpleTestCase. |
Returns
| Type | Description |
|---|---|
type | The decorated class with updated setting metadata attached. |