-
Notifications
You must be signed in to change notification settings - Fork 37
Open
Description
This would be useful in both tests, and as a general "something timed out, just try increasing the timeout a bit and see if it helps".
Need to keep a global reference that can temporarily (via context manager) or permanently (with function call) be set to a new value
Suggestion for implementation:
# core/_util.py
class OverridableTimeout(SupportsFloat):
def __init__(self, value: float):
self.value = value
def set_to(self, value: float) -> ContextManager:
original_value = self.value
self.value = value
@functools.context_manager
def revert():
yield
self.value = original_value
return revert
def __float__(self) -> float:
return self.value
DEFAULT_TIMEOUT = OverridableTimeout(10.0)
# test_my_device.py
from ophyd_async.core import DEFAULT_TIMEOUT
with DEFAULT_TIMEOUT.set_to(0.01):
with pytest.raises(TimeoutError):
# Somethere this calls a utility function with timeout=DEFAULT_TIMEOUT
await device.read()
# at runtime
>>> RE(bps.rd(device))
# uh oh it failed
>>> from ophyd_async.core import DEFAULT_TIMEOUT
>>> DEFAULT_TIMEOUT.set_to(20.0)
>>> RE(bps.rd(device))
# yay it workedAcceptance Criteria
- Code and tests written
- Docs page written to show usage in both tests and at runtime
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels