Skip to main content

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

AttributeTypeDescription
enable_exceptionException = nullStores 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

NameTypeDescription
**kwargsdictArbitrary keyword arguments representing the settings to be overridden.

Signature

def override_settings(
**kwargs: dict
) - > null

Parameters

NameTypeDescription
**kwargsdictArbitrary 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

TypeDescription
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

TypeDescription
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

NameTypeDescription
test_func`callabletype`

Returns

TypeDescription
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

NameTypeDescription
clstypeThe class to be decorated; must be a subclass of Django's SimpleTestCase.

Returns

TypeDescription
typeThe decorated class with updated setting metadata attached.