Decorators
π€ AI-Generated Content
This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
provide.foundation.testmode.decorators
¶
Functions¶
get_test_unsafe_features
¶
Get the registry of all test-unsafe features.
This is primarily used by validation tests to ensure all test-unsafe features are properly decorated.
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
Dictionary mapping function IDs to their metadata |
Example
features = get_test_unsafe_features() assert "process.title.set_process_title" in features
Source code in provide/foundation/testmode/decorators.py
is_test_unsafe
¶
Check if a function is registered as test-unsafe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., Any]
|
The function to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the function is decorated with @skip_in_test_mode |
Example
@skip_in_test_mode() def my_function(): ... pass
is_test_unsafe(my_function) True
Source code in provide/foundation/testmode/decorators.py
skip_in_test_mode
¶
skip_in_test_mode(
return_value: Any = None,
log_level: str = "debug",
reason: str | None = None,
) -> Callable[[F], F]
Decorator to skip function execution in test mode.
Marks a function as test-unsafe and automatically skips execution when running in test mode. The function is registered in a global registry for validation purposes.
This decorator is reusable for any scenario where you want to conditionally skip function execution based on runtime detection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
return_value
|
Any
|
Value to return when skipped (default: None) |
None
|
log_level
|
str
|
Log level for skip message (default: "debug") |
'debug'
|
reason
|
str | None
|
Optional custom reason for skipping (for logging) |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[F], F]
|
Decorated function that checks test mode before execution |
Example
@skip_in_test_mode(return_value=True) def set_system_state(value: str) -> bool: ... # This won't run in tests ... os.system(f"something {value}") ... return True
@skip_in_test_mode(return_value=None, reason="systemd not available in tests") def notify_systemd(status: str) -> None: ... systemd.notify(status)