Import
Overview
The factory test framework provides:- Step-based test execution with automatic sequencing
- Interactive UI elements (buttons, text input, selections)
- State management and data persistence between steps
- Error handling with automatic stop-on-fail behavior
- Result streaming to external systems
Classes
| Class | Description |
|---|---|
Step | Base class for defining test steps |
Failure | Exception class for test failures |
PersistentCache | Data persistence between test runs |
Functions
| Function | Description |
|---|---|
run() | Execute a sequence of test steps |
hash_file() | Calculate SHA1 hash of a file |
get_secret() | Get environment variable secret |
Step Class
Creating a Step
Create test steps by subclassingStep and implementing the run() method:
Step Properties
| Property | Type | Description |
|---|---|---|
state | dict | Shared state dictionary between steps |
StopOnFail | bool | If True (default), stop sequence on failure |
Step Methods
log(message, file=sys.stdout)
Log a message to stdout or stderr.
present_pass_fail_buttons(*, timeout=30)
Display Pass/Fail buttons and wait for operator response. Note: timeout is keyword-only.
bool - True if Pass clicked, False if Fail clicked
present_buttons(buttons, *, timeout=30)
Display custom buttons and wait for selection. Note: timeout is keyword-only.
| Parameter | Type | Description |
|---|---|---|
buttons | list | List of (label, value) tuples |
timeout | float | Timeout in seconds |
present_text_input(prompt, size=50, *, timeout=30)
Display a text input field. Note: timeout is keyword-only.
| Parameter | Type | Description |
|---|---|---|
prompt | str | Input prompt text |
size | int | Input field size (default: 50) |
timeout | float | Timeout in seconds |
str - User-entered text
present_select(label, choices, allow_multiple=False, *, timeout=30)
Display a dropdown selection. Note: timeout is keyword-only.
| Parameter | Type | Description |
|---|---|---|
label | str | Selection label |
choices | list | List of (label, value) tuples |
allow_multiple | bool | Allow multiple selections |
timeout | float | Timeout in seconds |
present_checkboxes(label, choices, *, timeout=30)
Display checkboxes for multiple selection. Note: timeout is keyword-only.
present_radios(label, choices, *, timeout=30)
Display radio buttons for single selection. Note: timeout is keyword-only.
update_heading(text)
Update the step heading text.
update_image(filename)
Display an image to the operator.
hide_image()
Hide the currently displayed image.
present_link(url, text=None)
Display a clickable link.
StopOnFail Behavior
By default, the test sequence stops when a step fails. Override this behavior:Failure Exception
UseFailure to indicate a test failure with a message:
run() Function
Execute a sequence of test steps:| Parameter | Type | Description |
|---|---|---|
steps | list | List of Step subclasses |
finalizer_cls | class | Optional Step class that always runs |
State Management
Shared State
Steps share astate dictionary:
Persistent Cache
For data that persists between test runs:Helper Functions
hash_file(path)
Calculate SHA1 hash of a file:
get_secret(name, default=None)
Get a secret from environment variables (prefixed with LAGER_SECRET_):
Examples
Complete Production Test
Interactive Configuration Step
Calibration with Cache
Notes
- Steps execute in order; sequence stops on first failure (unless
StopOnFail = False) - The finalizer step always runs, regardless of test pass/fail status
- State dictionary is shared between all steps in a sequence
- UI methods block until operator interaction or timeout
- Timeout raises
TimeoutErrorwhich is handled as a step failure FAILED_STEPis automatically set in state when a step fails- Cache data persists across test runs (stored on disk)
- The framework integrates with Lager’s streaming result system

