Metadata with python plugin

I am programming fully with the python-plugin and I try to add Metadata to my Result.csv - but I do not understand how, and the python-examples do not cover this topic.

My goal is something similar as requested here: https://forum.opentap.io/t/saving-duts-and-intruments-in-results
i.e. I would like to store DUT and Instrument information (aswell as other properties) into the result.csv file. As I understood this can be achieved easily via Metadata, however I don’t know how to use this feature within the python-plugin.

I tried to add a MetaDataAttribute to a property, i.e.:
abc = property(Double, 1) .add_attribute(OpenTap.MetaDataAttribute(True)) .add_attribute(OpenTap.Display(“abc_disp”, “abc”)), however this fails with "Unable to cast object of type ‘OpenTap.MetaDataAttribute’ to type ‘System.Type’.

Could someone point me in a direction on how to achieve this?

Hi @bernhard.lettner,

I think you just need to remove the “Attribute” part from the attribute. This works for me:

# I modified the BasicDut example to add metadata attribute.
class BasicDut(Dut):
    # Add a Firmware version setting which can be configured by the user.
    
    Firmware = property(String, "1.0.2")\
        .add_attribute(OpenTap.Display( "Firmware Version", "The firmware version of the DUT.", "Common"))\
        .add_attribute(OpenTap.MetaData(True))

Hi @rolf_madsen, thanks for your reply and code example!

I tried this, and now the code runs without obvious errors. However, the Metadata is still not stored to the results.csv file.

As Result Listener I am using Text/CSV and Text/Text Log.
In my code, I only append this line at the end of my Test-step:

# publish results:
self.PublishResult("example_resultListener", ["cMeas", "val1"], [val, val1])

Do you have any other steps in your code / am I missing some commands?