Test Options
Reference for test.configure() in OpenHTF — test name, stop_on_first_failure, failure_exceptions, default_dut_id, diagnosers and output_callbacks — plus Test.execute() arguments.
Last updated · Verified with OpenHTF 1.6.1
Test-wide switches live on TestOptions and are set with test.configure(**kwargs) before test.execute().
import openhtf as htf
class InstrumentTimeout(Exception):
pass
def measure(test):
return htf.PhaseResult.CONTINUE
def main():
test = htf.Test(measure)
test.configure(
name="PCB01 functional test",
stop_on_first_failure=True,
failure_exceptions=[InstrumentTimeout],
default_dut_id="NO_SERIAL",
)
test.execute(lambda: "SN1234")
if __name__ == "__main__":
main()Options
namestrTest name written to metadata.test_name. Default 'openhtf_test'. Passing test_name= as a keyword to htf.Test() sets the same field.
stop_on_first_failureboolStop the test as soon as any measurement fails validation. Default False — by default OpenHTF runs every phase and reports all failures. Also settable via the stop_on_first_failure configuration key, which is handy for toggling it per station. Finer control: checkpoints.
failure_exceptionslist[type[Exception]]Exceptions that should mark the run FAIL instead of ERROR. By default any unhandled exception in a phase ends the test with outcome ERROR (a problem with the test, not the DUT). List the exception types that mean "the DUT is bad" — a timeout waiting for the DUT to boot, a protocol error from the DUT — and the outcome becomes FAIL, which keeps yield statistics honest.
default_dut_idstrDUT ID used if neither the start trigger nor any phase set one. Default 'UNKNOWN_DUT'. See the ignore early-canceled tests example.
diagnoserslist[BaseTestDiagnoser]Test-level diagnosers that run after all phases with the full record.
output_callbackslist[callable]Replace the callback list. Prefer test.add_output_callbacks(...), which appends; pass [] here to clear.
test.configure() also parses command-line arguments once (-v, --config-file, --config-help, see CLI flags) and configures logging, so call it before any manual argparse of your own, or use parents=[htf.util.argv.module_parser()]-style composition.
Test.execute()
test.execute(test_start=None, profile_filename=None) -> booltest_startphase or callableEither a trigger phase (typically user_input.prompt_for_test_start()) or a zero-argument function returning the DUT ID (lambda: "SN1234"). If omitted, the DUT ID must be set by a phase or falls back to default_dut_id. See Device Under Test.
profile_filenamestrWrite cProfile statistics of the run to this file. Useful to find a slow phase.
returnsboolTrue if the outcome is PASS, else False. Lets a wrapper script exit non-zero on failure.
execute() runs one DUT. For a station that tests units back to back, loop around it — the frontend example does this five times with the Operator UI open.
Metadata
Keyword arguments to htf.Test(*phases, **metadata) are stored in test_record.metadata. config is reserved. Details on the Test Record page.
Related configuration keys
Some behaviour is configured through the configuration system rather than configure(): station_id, allow_unset_measurements, capture_source, station_server_port.
Related
Configuration
Explore how to manage test settings with OpenHTF's configuration module using in-code definitions or external configuration files.
CLI flags
Every command-line flag an OpenHTF test script accepts — -v verbosity, --config-file, --config-value, --config-help — and the dashboard_server flags, with how to combine them with your own argparse.