reframe icon indicating copy to clipboard operation
reframe copied to clipboard

Allow settings variables with implicit conversions in the class body

Open vkarak opened this issue 3 years ago • 0 comments

The current test syntax allows to define variables as strings and these are implicitly converted to a special type of a backend. An example is the build_system variable where users can write in their test:

class MyTest(RegressionTest):
    @run_before('compile')
    def setup_build(self):
        self.build_system = 'CMake'
        self.build_system.config_opts = ['-DCMAKE_FOO']

However, the following is not valid:

class MyTest(RegressionTest):
    build_system = 'CMake'
    build_system.config_opts = ['-DCMAKE_FOO']

Python will complain that str has no attribute config_opts. This is happening because the implicit conversion that the descriptor does does not work at this point.

To support this, we need to impose the conversion at the place of definition, which can be done, but also we need to properly handle inheritance, since the build_system variable is defined in a superclass. The problem with the current implementation is that inheritance of variables is happening at later stage, after the class body has executed. I believe that we can inherit the variable namespace already in the metaclass' __prepare__ method, since we already have access to the base classes. However, this requires a substantial refactoring of how namespaces work, but I tend to believe that if we inherit the variable (and parameter and fixture namespaces) early enough, the whole logic of namespace handling will be simplified.

vkarak avatar Jun 03 '22 15:06 vkarak