Examples

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.

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()
Terminal
$ 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

On this page

First-pass yield
0%4.1
Track with TofuPilot