Skip to content

Commit f6d5470

Browse files
committed
Fix behaviour of set_var_default() when setting a variable after test init
1 parent 6e60957 commit f6d5470

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

reframe/core/pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ def set_var_default(self, name, value):
13691369
if name not in var_space:
13701370
raise ValueError(f'no such variable: {name!r}')
13711371

1372-
if not var_space[name].is_defined():
1372+
if not hasattr(self, name):
13731373
setattr(self, name, value)
13741374

13751375
@loggable

unittests/test_pipeline.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1980,18 +1980,21 @@ def test_set_var_default():
19801980
class _X(rfm.RunOnlyRegressionTest):
19811981
foo = variable(int, value=10)
19821982
bar = variable(int)
1983+
zoo = variable(int)
19831984

19841985
@run_after('init')
19851986
def set_defaults(self):
19861987
self.set_var_default('foo', 100)
19871988
self.set_var_default('bar', 100)
1988-
1989+
self.zoo = 1
1990+
self.set_var_default('zoo', 100)
19891991
with pytest.raises(ValueError):
19901992
self.set_var_default('foobar', 10)
19911993

19921994
x = _X()
19931995
assert x.foo == 10
19941996
assert x.bar == 100
1997+
assert x.zoo == 1
19951998

19961999

19972000
def test_hashcode():

0 commit comments

Comments
 (0)