Skip to content
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
44 changes: 31 additions & 13 deletions reframe/core/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ def _validate_test(cls):
raise ValueError(f'decorated test ({cls.__qualname__!r}) has one or '
f'more undefined parameters')

conditions = [VersionValidator(v) for v in cls._rfm_required_version]
if (cls._rfm_required_version and
not any(c.validate(osext.reframe_version()) for c in conditions)):

getlogger().warning(f"skipping incompatible test "
f"'{cls.__qualname__}': not valid for ReFrame "
f"version {osext.reframe_version().split('-')[0]}")
return False

return True


def simple_test(cls):
'''Class decorator for registering tests with ReFrame.
Expand All @@ -101,10 +112,9 @@ def simple_test(cls):

.. versionadded:: 2.13
'''
_validate_test(cls)

for _ in cls.param_space:
_register_test(cls)
if _validate_test(cls):
for _ in cls.param_space:
_register_test(cls)

return cls

Expand Down Expand Up @@ -139,14 +149,14 @@ def parameterized_test(*inst):
)

def _do_register(cls):
_validate_test(cls)
if not cls.param_space.is_empty():
raise ValueError(
f'{cls.__qualname__!r} is already a parameterized test'
)
if _validate_test(cls):
if not cls.param_space.is_empty():
raise ValueError(
f'{cls.__qualname__!r} is already a parameterized test'
)

for args in inst:
_register_test(cls, args)
for args in inst:
_register_test(cls, args)

return cls

Expand Down Expand Up @@ -187,6 +197,12 @@ def required_version(*versions):
These should be written as ``3.5.0`` and ``3.5.0-dev.0``.

'''
warn.user_deprecation_warning(
"the '@required_version' decorator is deprecated; please set "
"the 'require_version' parameter in the class definition instead",
from_version='3.7.0'
)

if not versions:
raise ValueError('no versions specified')

Expand All @@ -198,8 +214,10 @@ def _skip_tests(cls):
mod.__rfm_skip_tests = set()

if not any(c.validate(osext.reframe_version()) for c in conditions):
getlogger().info('skipping incompatible test defined'
' in class: %s' % cls.__name__)
getlogger().warning(
f"skipping incompatible test '{cls.__qualname__}': not valid "
f"for ReFrame version {osext.reframe_version().split('-')[0]}"
)
mod.__rfm_skip_tests.add(cls)

return cls
Expand Down
49 changes: 45 additions & 4 deletions reframe/core/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,49 @@ class RegressionTest(RegressionMixin, jsonext.JSONSerializable):
This class provides the implementation of the pipeline phases that the
regression test goes through during its lifetime.

.. warning::
.. versionchanged:: 3.4.2
Multiple inheritance with a shared common ancestor is not allowed.
This class accepts parameters at the *class definition*, i.e., the test
class can be defined as follows:

.. code-block:: python

class MyTest(RegressionTest, param='foo', ...):

where ``param`` is one of the following:

:param pin_prefix: lock the test prefix to the directory where the current
class lives.

:param require_version: a list of ReFrame version specifications that this
test is allowed to run. A version specification string can have one of
the following formats:

- ``VERSION``: Specifies a single version.
- ``{OP}VERSION``, where ``{OP}`` can be any of ``>``, ``>=``, ``<``,
``<=``, ``==`` and ``!=``. For example, the version specification
string ``'>=3.5.0'`` will allow the following test to be loaded
only by ReFrame 3.5.0 and higher. The ``==VERSION`` specification
is the equivalent of ``VERSION``.
- ``V1..V2``: Specifies a range of versions.

The test will be selected if *any* of the versions is satisfied, even
if the versions specifications are conflicting.

:param special: allow pipeline stage methods to be overriden in this class.

.. note::
.. versionchanged:: 2.19
Base constructor takes no arguments.

.. versionadded:: 3.3
The ``pin_prefix`` class definition parameter is added.

.. versionadded:: 3.7.0
The ``require_verion`` class definition parameter is added.

.. warning::
.. versionchanged:: 3.4.2
Multiple inheritance with a shared common ancestor is not allowed.

'''

def disable_hook(self, hook_name):
Expand Down Expand Up @@ -805,10 +840,16 @@ def __getattribute__(self, name):
return super().__getattribute__(name)

@classmethod
def __init_subclass__(cls, *, special=False, pin_prefix=False, **kwargs):
def __init_subclass__(cls, *, special=False, pin_prefix=False,
require_version=None, **kwargs):
super().__init_subclass__(**kwargs)
cls._rfm_override_final = special

if require_version:
cls._rfm_required_version = require_version
elif not hasattr(cls, '_rfm_required_version'):
cls._rfm_required_version = []

# Insert the prefix to pin the test to if the test lives in a test
# library with resources in it.
if pin_prefix:
Expand Down
7 changes: 4 additions & 3 deletions unittests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ def test_load_error(loader):


def test_load_bad_required_version(loader):
with pytest.raises(ValueError):
loader.load_from_file('unittests/resources/checks_unlisted/'
'no_required_version.py')
with pytest.warns(ReframeDeprecationWarning):
with pytest.raises(ValueError):
loader.load_from_file('unittests/resources/checks_unlisted/'
'no_required_version.py')


def test_load_bad_init(loader):
Expand Down