You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/testing.md
+36-4Lines changed: 36 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ For testing purposes, **Monkay** provides three context manager methods that all
15
15
16
16
### Available Context Managers:
17
17
18
-
1.**`with_settings(settings)`**: Temporarily overwrites the settings for the scope of the context.
18
+
1.**`with_settings(settings, *, evaluate_settings_with=None)`**: Temporarily overwrites the settings for the scope of the context. Optionally evaluate settings with provided parameters as dict. Enable evaluation by providing a dict.
19
19
2.**`with_extensions(extensions_dict, *, apply_extensions=False)`**: Temporarily overwrites the extensions for the scope. The `apply_extensions` flag controls whether extensions are applied during the overwrite.
20
20
3.**`with_instance(instance, *, apply_extensions=False, use_extensions_overwrite=True)`**: Temporarily overwrites the instance for the scope. You can also apply extensions and control the overwrite behavior using the respective flags.
21
21
@@ -26,10 +26,10 @@ These context managers provide a flexible way to test different configurations o
with monkay.with_settings({"setting_name": "new_value"}):
31
+
# Overwrite settings temporarily and evaluate it
32
+
with monkay.with_settings({"setting_name": "new_value"}, evaluate_settings_with={}):
33
33
assert monkay.settings.setting_name =="new_value"
34
34
35
35
# Overwrite extensions temporarily
@@ -43,6 +43,38 @@ with monkay.with_instance(new_instance, apply_extensions=False):
43
43
44
44
These context managers are especially useful for writing isolated and repeatable tests, where you may want to modify the environment without affecting the global state.
45
45
46
+
### Full overwrite
47
+
48
+
If multiple attributes should be simulated, e.g. for a virtual monkay environment, you can use
49
+
`with_full_overwrite`. The advantage: you have already the right order set.
50
+
Note: when not enabling a feature in monkay it will cause an error to provide a parameter for it.
51
+
52
+
#### Parameters
53
+
54
+
Parameters which need a feature enabled when creating the monkay instance:
55
+
56
+
**extensions** - Set an extra extensions set like with `with_extensions`. You might want to set it to {} for a clean extensions set.
57
+
**settings** - Overwrite the settings if specified. It types matches the `with_settings` contextmanager.
58
+
**instance** - Overwrite the instance if specified. It types matches the `with_instance` contextmanager.
59
+
60
+
Extra parameters:
61
+
62
+
-**apply_extensions** - Apply extensions. Only used when `extensions` parameter is used.
63
+
-**evaluate_settings_with** - Pass options to `with_settings` parameter `evaluate_settings_with`. Only used when `settings` parameter is used.
Copy file name to clipboardExpand all lines: docs/tutorial.md
+15-38Lines changed: 15 additions & 38 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,49 +26,18 @@ pip install monkay
26
26
Below is an example of how to set up **Monkay** in your project. You can use **Monkay** to manage dynamic imports, lazy loading, settings, extensions, and more.
In `main.py`, the application is initialized by evaluating preloads and settings, ensuring that all required dependencies are loaded before use.
@@ -79,7 +48,7 @@ In `main.py`, the application is initialized by evaluating preloads and settings
79
48
80
49
After providing **Monkay**, if you need more control over the `__all__` variable, you can disable the automatic update of `__all__` by setting `skip_all_update=True`. You can later update it manually using `Monkay.update_all_var`.
81
50
82
-
**Warning**: Using `settings_preloads_name` or `settings_extensions_name` can sometimes cause circular dependency issues. To avoid such issues, ensure that you call `evaluate_settings()` later in the setup process. For more information, refer to [Settings Preloads and Extensions](#settings-preloads-andextensions).
51
+
**Warning**: Using `settings_preloads_name` or `settings_extensions_name` can sometimes cause circular dependency issues. To avoid such issues, ensure that you call `evaluate_settings()` later in the setup process. For more information, refer to [Settings Preloads and Extensions](#settings-extensions-and-preloads).
0 commit comments