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.

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

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?