Skip to content

Commit

Permalink
Merge pull request #3293 from Blanca-Fuentes/error_reporting
Browse files Browse the repository at this point in the history
[enhancement] Report the undefined parameters if an instantiation of an abstract test or fixture is attempted
  • Loading branch information
vkarak authored Nov 12, 2024
2 parents 9370543 + f961841 commit ae27651
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
7 changes: 3 additions & 4 deletions reframe/core/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

__all__ = ['simple_test']


import inspect
import sys
import traceback
Expand Down Expand Up @@ -171,10 +170,10 @@ def _validate_test(cls):

if (cls.is_abstract()):
getlogger().warning(
f'skipping test {cls.__qualname__!r}: '
f'test has one or more undefined parameters'
f'skipping test {cls.__qualname__!r}: ' +
'the following parameters are undefined: ' +
', '.join(cls.param_space.undefined_params())
)
return False

conditions = [VersionValidator(v) for v in cls._rfm_required_version]
if (cls._rfm_required_version and
Expand Down
9 changes: 2 additions & 7 deletions reframe/core/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,6 @@ def uninst_tests(self):
'''Get the uninstantiated tests of this registry'''
return self._registry.keys()

def _filter_valid_partitions(self, candidate_parts):
return [p for p in candidate_parts if p in self._env_by_part]

def _filter_valid_environs(self, part, candidate_environs):
return [e for e in cadidate_environs if e in self._env_by_part[part]]

def _is_registry(self, other):
if not isinstance(other, FixtureRegistry):
raise TypeError('other is not a FixtureRegistry')
Expand Down Expand Up @@ -776,7 +770,8 @@ def __init__(self, cls, *, scope='test', action='fork', variants='all',
# Check that the fixture class is not an abstract test.
if cls.is_abstract():
raise ValueError(
f'class {cls.__qualname__!r} has undefined parameters'
f'fixture {cls.__qualname__!r} has undefined parameters: ' +
', '.join(cls.param_space.undefined_params())
)

# Validate the scope
Expand Down
9 changes: 7 additions & 2 deletions reframe/core/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def update(self, other):
self.values = tuple(filt_vals) + self.values
except TypeError:
raise ReframeSyntaxError(
f"'filter_param' must return an iterable"
"'filter_param' must return an iterable"
) from None

def is_abstract(self):
Expand Down Expand Up @@ -307,7 +307,7 @@ def inject(self, obj, cls=None, params_index=None):
try:
# Get the parameter values for the specified variant
param_values = self.__param_combinations[params_index]
except IndexError as no_params:
except IndexError:
raise RuntimeError(
f'parameter space index out of range for '
f'{obj.__class__.__qualname__}'
Expand All @@ -333,6 +333,11 @@ def defines(self, name):
'''
return name in self.params and not self.params[name].is_abstract()

def undefined_params(self):
'''Return a list of all undefined parameters.'''
return [name for name, param in self.params.items()
if param.is_abstract()]

def __iter__(self):
'''Create a generator object to iterate over the parameter space
Expand Down
6 changes: 5 additions & 1 deletion unittests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import reframe as rfm
from reframe.core.exceptions import ReframeSyntaxError
import reframe.core.decorators as decorators


class NoParams(rfm.RunOnlyRegressionTest):
Expand Down Expand Up @@ -48,10 +49,13 @@ class MyTest(TwoParams):

def test_abstract_param():
class MyTest(Abstract):
pass
# Add another abstract parameter
P2 = parameter()

assert MyTest.param_space['P0'] == ()
assert MyTest.param_space['P1'] == ('b',)
assert MyTest.param_space['P2'] == ()
assert MyTest.param_space.undefined_params() == ['P0', 'P2']


def test_param_override():
Expand Down

0 comments on commit ae27651

Please sign in to comment.