Skip to content

Commit cca262b

Browse files
authored
Merge pull request #2012 from jjotero/bugfix/use-require-keyword
[bugfix] Restrict use of `required` keyword
2 parents 830abc6 + 5631c9f commit cca262b

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

reframe/core/meta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class was created or even at the instance level (e.g. doing
243243

244244
blacklist = [
245245
'parameter', 'variable', 'bind', 'run_before', 'run_after',
246-
'require_deps'
246+
'require_deps', 'required'
247247
]
248248
for b in blacklist:
249249
namespace.pop(b, None)

reframe/core/variables.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,11 @@ def extend(self, cls):
493493
if key in self.vars:
494494
self.vars[key].define(value)
495495
_assigned_vars.add(key)
496+
elif value is Undefined:
497+
# Cannot be set as Undefined if not a variable
498+
raise ValueError(
499+
f'{key!r} has not been declared as a variable'
500+
)
496501

497502
# Delete the vars from the class __dict__.
498503
for key in _assigned_vars:

unittests/test_meta.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class MyTest(rfm.RegressionTest):
2020
run_before('run')(ext)
2121
run_after('run')(ext)
2222
require_deps(ext)
23+
v = required
2324

2425
def __init__(self):
2526
assert not hasattr(self, 'parameter')
@@ -28,6 +29,7 @@ def __init__(self):
2829
assert not hasattr(self, 'run_before')
2930
assert not hasattr(self, 'run_after')
3031
assert not hasattr(self, 'require_deps')
32+
assert not hasattr(self, 'required')
3133

3234
MyTest()
3335

unittests/test_variables.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ def __init__(self):
170170
MyTest()
171171

172172

173+
def test_required_non_var():
174+
msg = "'not_a_var' has not been declared as a variable"
175+
with pytest.raises(ValueError, match=msg):
176+
class Foo(rfm.RegressionTest):
177+
not_a_var = required
178+
179+
173180
def test_invalid_field():
174181
class Foo:
175182
'''An invalid descriptor'''

0 commit comments

Comments
 (0)