-
Notifications
You must be signed in to change notification settings - Fork 117
Description
With the new -S CLI option to set test variables, these are set after the class is created. However, there might be some cases where one would be interested in setting them in the class body itself, for example:
@rfm.simple_test
class MyTest(rfm.RunOnlyRegressionTest):
min = variable(int, value=2)
max = variable(int, value=5)
# Parameterise number of nodes
num_nodes = parameter((1 << i for i in range(int(min), int(max))))
...Here the user cannot control the parameterisation through the CLI option -S, because that value gets injected after the class body is executed. However, one could control the min and max default value assigned in the class body using environment variables:
@rfm.simple_test
class MyTest(rfm.RunOnlyRegressionTest):
min = variable(int, value=2)
max = variable(int, value=5)
# Update the test variables from their associated environment variables
if 'MYTEST_min' in os.environ:
min = int(os.environ['MYTEST_min'])
if 'MYTEST_max' in os.environ:
min = int(os.environ['MYTEST_max'])
# Parameterise number of nodes
num_nodes = parameter((1 << i for i in range(int(min), int(max))))
...This being said, I wonder if it's worth extending the variable interface to simplify this:
@rfm.simple_test
class MyTest(rfm.RunOnlyRegressionTest):
min = variable(int, value=2, envvar='MYTEST_min')
max = variable(int, value=5, envvar='MYTEST_max')
# Parameterise number of nodes
num_nodes = parameter((1 << i for i in range(int(min), int(max))))
...Here envvar supersedes value if envvar is present. The solution to the type casting problem is trivial here, since the types are available.
Thanks to @mahendrapaipuri for bringing up the use case