Reference
shared.dry_run.context ¶
Dry-run context manager implementation using contextvars for thread-safe operation.
This module provides a context manager to set dry-run mode and a helper function to check if the current execution context is in dry-run mode.
Key behaviors: - Once dry-run is enabled, it cannot be disabled in nested contexts - Context manager is safely nestable
Limitations: - Dry-run is not passed down to child threads, if you do multi-threading, ensure you pass the current dry-run state to child threads
dry_run ¶
Dry-run context manager.
Once enabled, dry-run mode cannot be disabled in nested contexts.
Dry-run is not passed down to child threads, if you do multi-threading, ensure you pass the current dry-run state to child threads manually.
Example
with dry_run(): # code runs in dry-run mode assert is_dry_run()
with dry_run():
# still in dry run in inner contexts
assert is_dry_run()
# even when exiting the inner context
assert is_dry_run()
disabled only when exiting the outermost context¶
assert not is_dry_run()
Source code in shared/dry_run/context.py
is_dry_run ¶
Check if the current execution context is in dry-run mode.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if currently in dry-run mode, False otherwise. |
Example
with dry_run(): assert is_dry_run()
assert not is_dry_run()
Source code in shared/dry_run/context.py
shared.dry_run.dry_run ¶
Dry-run context manager.
Once enabled, dry-run mode cannot be disabled in nested contexts.
Dry-run is not passed down to child threads, if you do multi-threading, ensure you pass the current dry-run state to child threads manually.
Example
with dry_run(): # code runs in dry-run mode assert is_dry_run()
with dry_run():
# still in dry run in inner contexts
assert is_dry_run()
# even when exiting the inner context
assert is_dry_run()
disabled only when exiting the outermost context¶
assert not is_dry_run()
Source code in shared/dry_run/context.py
shared.dry_run.is_dry_run ¶
Check if the current execution context is in dry-run mode.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if currently in dry-run mode, False otherwise. |
Example
with dry_run(): assert is_dry_run()
assert not is_dry_run()