Attachments

Attach files collected during execution to the test record.

Illustration of file attachments process in OpenHTF, showcasing TofuPilot integration for managing attached files.

Overview

Hardware tests often generate extra data, such as images, that can't be captured as measurements. OpenHTF allows you to attach these files to the test record.

With the TofuPilot integration, attachments are uploaded automatically and you can access and download them directly from your TofuPilot workspace.

Files

You can attach binary data or files generated during the test.

main.py

import openhtf as htf

def phase_attachment(test):
    # Attach a binary log with the identifier "test_attachment"
    test.attach("test_attachment", "This is test log data.".encode("utf-8"))
    return htf.PhaseResult.CONTINUE

def main():
    test = htf.Test(phase_attachment)
    test.execute(lambda: "PCB0001")

if __name__ == "__main__":
    main()

Files by path

You can attach larger or pre-existing files from disk or URL.

main.py

import openhtf as htf

def phase_file_attachment(test):
    test.attach_from_file("/path/to/your/logfile.txt")
    return htf.PhaseResult.CONTINUE

def main():
    test = htf.Test(phase_file_attachment)
    test.execute(lambda: "PCB0001")

if __name__ == "__main__":
    main()

TofuPilot integration

The TofuPilot integration is natively compatible with OpenHTF phases.

To integrate TofuPilot, install the open-source client:

pip install tofupilot

Add it to your test like this:

main.py

import openhtf as htf
from tofupilot.openhtf import TofuPilot

def phase_file_attachment(test):
    test.attach_from_file("/path/to/your/logfile.txt")
    return htf.PhaseResult.CONTINUE

def main():
    test = htf.Test(phase_file_attachment)
    with TofuPilot(test):                   # just works™️
      test.execute(lambda: "PCB001")

if __name__ == "__main__":
    main()

You can access attachments in a dedicated section of the run page, where you can open them in the browser or download them.

Screenshot of OpenHTF attachments page showing file management options and TofuPilot integration.

Advanced use cases

You can use extended features for attachements advanced use cases.

Access attachments during execution

You can load and access attached files during test execution.

main.py

import openhtf as htf

def phase_attachment(test):
    # Attach some data
    test.attach("test_attachment", "Attachment data".encode("utf-8"))

    # Retrieve and print the attached data
    test_attachment = test.get_attachment("test_attachment")
    print(test_attachment.data)

    return htf.PhaseResult.CONTINUE

def main():
    test = htf.Test(phase_attachment)
    test.execute(lambda: "PCB0001")

if __name__ == "__main__":
    main()

Was this page helpful?