Stop on First Failure Example
The upstream stop_on_first_failure.py example — end the test at the first failed measurement using test.configure(stop_on_first_failure=True) or the equivalent configuration key.
Last updated · Verified with OpenHTF 1.6.1
Two ways to make OpenHTF stop as soon as a measurement fails. Based on examples/stop_on_first_failure.py.
import openhtf as htf
from openhtf.output.callbacks import console_summary
from openhtf.plugs import user_input
from openhtf.util import configuration
from openhtf.util import validators
CONF = configuration.CONF
@htf.measures('number_sum', validators=[validators.in_range(0, 5)])
def add_numbers_fails(test):
test.logger.info('Add numbers 2 and 4')
test.measurements.number_sum = 2 + 4 # 6 > 5: FAIL
# Never runs: the previous phase failed a measurement.
@htf.measures(htf.Measurement('hello_world_measurement'))
def hello_world(test):
test.logger.info('This phase will not be run since previous phase failed')
test.measurements.hello_world_measurement = 'Hello World!'
def main():
test = htf.Test(add_numbers_fails, hello_world)
test.add_output_callbacks(console_summary.ConsoleSummary())
# Option 1: in code
test.configure(stop_on_first_failure=True)
# Option 2: configuration key — same effect, switchable per station
# CONF.load(stop_on_first_failure=True)
test.execute(test_start=user_input.prompt_for_test_start())
if __name__ == '__main__':
main()$ python stop_on_first_failure.py
Enter a DUT ID in order to start the test.
--> SN1
openhtf_test:FAIL
failed phase: add_numbers_fails [ran for 0.00 sec]
failed_item: number_sum (Outcome.FAIL)
measured_value: 6
validators:
validator: 0 <= x <= 5
======================= test: openhtf_test outcome: FAIL ======================hello_world does not appear in the record.
What it shows
test.configure(stop_on_first_failure=True)A TestOptions field. The phase whose measurement failed finishes; nothing after it runs. Test Options →
CONF.load(stop_on_first_failure=True)The same switch through the configuration system, so --config-value stop_on_first_failure=true or a per-station YAML file can turn it on during debugging and off in production. Configuration →
Inline validators=[...]The kwargs declaration form with a validator object from openhtf.util.validators. Measurements example →
When not to use it
On a production line you usually want all cheap failures recorded in one pass so the repair technician sees everything wrong with the unit. Reserve stop_on_first_failure for debugging, and use checkpoints before expensive phases in production.
Next
Repeat
The upstream repeat.py example — retry a phase on a plug exception with PhaseResult.REPEAT, and cap retries on a bad result with PhaseOptions(repeat_limit=5).
Ignore early-canceled tests
The upstream ignore_early_canceled_tests.py example — subclass OutputToJSON to skip writing records for tests aborted (Ctrl-C) before an operator entered a DUT ID, using default_dut_id.