Skip to content

The parameterize directive

Richard R. Drake edited this page Jun 8, 2022 · 3 revisions

This section is for reference; see parameterizing a test for more detail on how to use parameters.

To parameterize on a single parameter name:

#VVT: parameterize : name = value1 value2 value3

This will create three test instances, one with name=value1, one with name=value2, and one with name=value3.

A parameter name must be a valid shell or Python variable.

To parameterize on grouped parameter names:

#VVT: parameterize : nameA,nameB = valueA1,valueB1 valueA2,valueB2 valueA3,valueB3

This will create three test instances:

  • nameA=valueA1 and nameB=valueB1
  • nameA=valueA2 and nameB=valueB2
  • nameA=valueA3 and nameB=valueB3

Line continuation is frequently used with parameterized grouping to make it more readable:

#VVT: parameterize : nameA, nameB = valueA1, valueB1
#VVT::                              valueA2, valueB2
#VVT::                              valueA3, valueB3

Multiple parameterize directives

When multiple parameterize directives are given, the Cartesian product of each is taken to form the set of test instances. For example,

#VVT: parameterize : nameA = valueA1 valueA2
#VVT: parameterize : nameB = valueB1 valueB2 valueB3

This will produce 2*3=6 test instances:

  • nameA=valueA1 and nameB=valueB1
  • nameA=valueA1 and nameB=valueB2
  • nameA=valueA1 and nameB=valueB3
  • nameA=valueA2 and nameB=valueB1
  • nameA=valueA2 and nameB=valueB2
  • nameA=valueA2 and nameB=valueB3

Allowable attributes

The allowable common attributes are "testname", "platform", and "option". These decide whether the directive is processed or not.

The "staged" attribute causes the test instances corresponding to the parameter values to be run sequentially and in the same execution directory. See the section on Using staging in parameterized tests for more information, but an example syntax is

#VVT: parameterize (staged) : name = value1 value2 value3

The "autotype" attribute affects the Python type of the parameter variable in the vvtest_util.py file. Consider

#VVT: parameterize (autotype) : np = 1 4 16
#VVT: parameterize (autotype) : size = 0.1 0.01 0.001

import vvtest_util as vvt
print ( 'type of np '+str(type(vvt.np)) )
print ( 'type of size '+str(type(vvt.size)) )

In this case, the Python type of the np variable will be 'int' and size will be 'float'.

The "autotype" mechanism does this:

  1. Try casting each parameter value to an 'int'. If success, use type 'int'
  2. Try casting each parameter value to a 'float'. If success, use type 'float'
  3. If neither of those, then use type 'str'

Without "autotype" the Python type of parameters is always a string.

Clone this wiki locally