Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] Fix behaviour of set_var_default() when setting a variable after test initialisation #3050

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion reframe/core/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ def set_var_default(self, name, value):
if name not in var_space:
raise ValueError(f'no such variable: {name!r}')

if not var_space[name].is_defined():
if not hasattr(self, name):
setattr(self, name, value)

@loggable
Expand Down
5 changes: 4 additions & 1 deletion unittests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1980,18 +1980,21 @@ def test_set_var_default():
class _X(rfm.RunOnlyRegressionTest):
foo = variable(int, value=10)
bar = variable(int)
zoo = variable(int)

@run_after('init')
def set_defaults(self):
self.set_var_default('foo', 100)
self.set_var_default('bar', 100)

self.zoo = 1
self.set_var_default('zoo', 100)
with pytest.raises(ValueError):
self.set_var_default('foobar', 10)

x = _X()
assert x.foo == 10
assert x.bar == 100
assert x.zoo == 1


def test_hashcode():
Expand Down