OpenHTF, the open-source hardware testing framework in Python

OpenHTF (Open Hardware Testing Framework) is an open-source Python framework for hardware testing, originally created at Google. Phases, measurements with limits, plugs for instruments, an operator UI and JSON test records.

OpenHTF is a Python framework for writing hardware test scripts: the functional, end-of-line and burn-in tests that decide whether a board or a product passes. It was originally created at Google and is used from design verification through validation to manufacturing.

These docs are maintained by TofuPilot, which runs OpenHTF scripts on test stations and stores every run. Not affiliated with Google (see the disclaimer).

Start here

How a test is built

OpenHTF tests are Python scripts that run a series of test steps on a Device Under Test (DUT), taking measurements along the way. The framework handles setup, execution and teardown, records everything, and produces a pass/fail outcome.

Phases

Test steps — plain Python functions — that perform actions and return pass, fail, or skip. Phases →

Measurements

Values captured during phases, with optional validators (limits, regex, custom) that decide the outcome. Measurements →

Plugs

Reusable classes that wrap external hardware and software — instruments, the DUT's serial port, the operator. Plugs →

Test Record

Structured output with outcomes, measurements, logs and attachments, written by output callbacks to JSON or a database. Test Record →

main.py
import openhtf as htf
from openhtf.plugs import plug
from multimeter_plug import MultimeterPlug

@plug(multimeter=MultimeterPlug)
@htf.measures(
    htf.Measurement("voltage")
    .in_range(3.0, 3.5)
    .with_units("V"))
def test_voltage(test, multimeter):
    voltage = multimeter.measure_voltage()
    test.measurements.voltage = voltage

def main():
    test = htf.Test(test_voltage)
    test.execute(lambda: "SN0001") # DUT S/N

if __name__ == "__main__":
    main()
multimeter_plug.py
from openhtf.plugs import BasePlug

class MultimeterPlug(BasePlug):
    # Simulate connecting to the multimeter
    def __init__(self):
        self.connected = True

    # Simulate measuring the voltage
    def measure_voltage(self):
        return 3.3

    # Simulate disconnecting from the multimeter
    # Called automatically by OpenHTF at test end
    def tearDown(self):
        self.connected = False

Go deeper

Frequently asked

On this page

Run it on your stations

$ tofupilot run .
✓ operator UI ready
$ git push
✓ stations updated
✓ runs uploaded

Same OpenHTF script, no code changes.

How it works