Parameterize programmatically

MicrosoftTeams-image (6)
In the editor there are three options given for parameterization. The “Parameterize…” option leads to a window where the scope and name of the parameter can be changed.

I have been trying to parameterize within a test plan programmatically with Python, and have been using ParameterExtensions.Parameterize() to do so. However, I have been running into issues when trying to parameterize with this function with wider scope than directly onto a parent. Is there a way to programmatically parameterize with the same capability as the “Parameterize…” option?

Hi @davihous,

You should be able to do exactly what Parameterize… can do.

However, a setting can only be parameterized unto a parent (parents parent, parent of that, and so on until you reach the test plan) of the step.

1 Like

Hi @rolf_madsen ,

The issue we have run into is when we are trying to programmatically parameterize onto a test step, in its own initialization.

Calling ParameterExtensions.Parameterize(myMember, self, mySourceStep, paramName) only works when mySourceStep is a direct child of self. When trying to parameterize while “skipping over” another step, i.e. when self has a child whose child is mySourceStep, the parameterization is removed, with the message:

Parameter; Information; Step mySourceStep is no longer a child step of the parameter owner. Removing from paramName.

To avoid leaking memory, some custom garbage collection mechanism is being used from time to time to clean up the parameters. This means that if the step is not connected to a test plan, the parameter will eventually get removed.

I can see this might cause the problem you see. Without being 100% sure, maybe you can try this to begin with:

token = OpenTap.ParameterManager.WithSanityCheckDelayed()
try:
     # ... do stuff with parameters.
finally:
   token.Dispose() ## remember this!

The issue seems to be that the python step I am creating hasn’t finished instantiating so it is unaware of it’s child steps children. I found a work around but it feels a bit odd.

The following code does not attach a grandchild steps parameter to the step I am creating

 member = OpenTap.TypeData.GetTypeData(childStepsChildStep).GetMember(param)
 OpenTap.ParameterExtensions.Parameterize(member, self, childStepsChildStep, param)

But if I pass it to a step that is a direct child of the step I am creating I can attach the parameter from there.

member = OpenTap.TypeData.GetTypeData(childStepsChildStep).GetMember(param)
OpenTap.ParameterExtensions.Parameterize(member, childStep, childStepsChildStep, param)
member = OpenTap.TypeData.GetTypeData(childStep).GetMember(param)
OpenTap.ParameterExtensions.Parameterize(member, self, childStep, param)

So it seems the step at instantiation is aware of it’s direct children but somehow not aware of it’s grandchildren