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
25 changes: 18 additions & 7 deletions reframe/core/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ class RegressionTest(metaclass=RegressionTestMeta):
#: taken.
#:
#: :type: :class:`str` or :class:`None`
#: :default: ``'src'``
#: :default: ``'src'`` if such a directory exists at the test level,
#: otherwise ``None``
#:
#: .. note::
#: .. versionchanged:: 2.9
Expand All @@ -211,6 +212,10 @@ class RegressionTest(metaclass=RegressionTestMeta):
#:
#: .. versionchanged:: 2.10
#: Support for Git repositories was added.
#:
#: .. versionchanged:: 3.0
#: Default value is now conditionally set to either ``'src'`` or
#: :class:`None`.
sourcesdir = fields.TypedField('sourcesdir', str, type(None))

#: The build system to be used for this test.
Expand Down Expand Up @@ -661,8 +666,13 @@ def __new__(cls, *args, **kwargs):
itertools.chain(args, kwargs.values()))
name += '_' + '_'.join(arg_names)

obj._rfm_init(name,
os.path.abspath(os.path.dirname(inspect.getfile(cls))))
# Determine the prefix
try:
prefix = cls._rfm_custom_prefix
except AttributeError:
prefix = os.path.abspath(os.path.dirname(inspect.getfile(cls)))

obj._rfm_init(name, prefix)
return obj

def __init__(self):
Expand Down Expand Up @@ -706,10 +716,11 @@ def _rfm_init(self, name=None, prefix=None):
self.local = False

# Static directories of the regression check
if prefix is not None:
self._prefix = os.path.abspath(prefix)

self.sourcesdir = 'src'
self._prefix = os.path.abspath(prefix)
if os.path.isdir(os.path.join(self._prefix, 'src')):
self.sourcesdir = 'src'
else:
self.sourcesdir = None

# Output patterns
self.sanity_patterns = None
Expand Down
13 changes: 13 additions & 0 deletions unittests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,16 @@ def partition_with_scheduler(name=None, skip_partitions=['kesch:pn']):
def has_sane_modules_system():
return not isinstance(rt.runtime().modules_system.backend,
modules.NoModImpl)


def custom_prefix(prefix):
'''Assign a custom prefix to a test.

This is useful in unit tests when we want to create tests on-the-fly and
associate them with existing resources.'''

def _set_prefix(cls):
cls._rfm_custom_prefix = prefix
return cls

return _set_prefix
Loading