run().
A step can drive hardware with the Lager Python API. It can also ask the operator for input, and it reports pass or fail.
A small suite
This suite has three steps. It also needs the fileimages/fixture.jpg in the suite.
Import the module
The suite can import the Factory module in any of these ways:How Stout runs the entry point
- Stout copies all suite files to a temporary folder on the box. It deletes the folder when the run ends.
- Stout runs the entry point as
__main__, with the suite folder as the working directory. - The folder of the entry point is first on
sys.path. The entry point can import the other Python files in the suite. - The Factory module reads the answers of the operator from standard input. Your code must not read standard input.
Steps
A step is a class that extendsStep and has a run() method. These class attributes control how the step shows in the dashboard.
Always set
DisplayName. Without it, the suite page and the run page can show different names for the step.
Rules for the step list
The dashboard reads the step list from the entry point without running it. For the dashboard to find your steps, follow these rules:- Define each step class at the top level of the entry point, as
class Name(Step):orclass Name(factory.Step):. - Write
DisplayName,Description,Image, andLinkas string literals. A string in parentheses can continue across lines. - List the steps in a top-level
STEPS = [...]list, with one class name on each line. - Pass the same list to
run().
STEPS list, the dashboard uses every step class in file order.
Pass and fail
- A step fails when its
run()method raises an exception or returnsFalse. - Any other return value counts as a pass. This includes
None. - After a step fails, the run stops. To continue after a failure, set
StopOnFail = Falseon the step. - An exception outside a step ends the whole run with an error.
Share data between steps
self.state is a dictionary that all steps in one run share. A step can store a value, such as a serial number, and a later step can read it.
Clean up after the run
run() accepts a second argument, a finalizer class. Stout runs the finalizer after the steps, also when a step fails. Use a finalizer to turn off power or to close connections.
Prompt the operator
Each of these methods shows a prompt and waits for the answer.
The text field does not accept an empty answer.
Time limits
timeout is a time limit in seconds. If nobody answers in time, Stout answers for the operator, and the console shows a message.
present_pass_fail_buttons()returnsFalse.present_buttons()returns theFaillabel if there is one. Otherwise it returns the last label.present_text_input(),present_radios(), andpresent_select()returnNone.present_checkboxes()returns[None].
Show information
Output from
print() also shows in the console during the run. After the run ends, the run page does not keep that output. To keep a message, use self.log().
Read variables and secrets
Before each run, Stout sends the variables and secrets for the box. See Variables and secrets. In a Factory suite, read a value withget_secret():
get_secret(name) returns the value from the environment. If the environment does not have the name, it reads the secrets file on the box. If neither one has the name, it returns an empty string.
Factory
Import a suite, run it, and read the results.
Lager Python API
Drive instruments from the steps of your suite.