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
16 changes: 14 additions & 2 deletions reframe/core/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,12 @@ def __new__(cls, *args, **kwargs):
if osext.is_interactive():
prefix = os.getcwd()
else:
prefix = os.path.abspath(os.path.dirname(inspect.getfile(cls)))
try:
prefix = cls._rfm_pinned_prefix
except AttributeError:
prefix = os.path.abspath(
os.path.dirname(inspect.getfile(cls))
)

obj._rfm_init(name, prefix)
return obj
Expand All @@ -736,10 +741,17 @@ def __init__(self):
pass

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

# Insert the prefix to pin the test to if the test lives in a test
# library with resources in it.
if pin_prefix:
cls._rfm_pinned_prefix = os.path.abspath(
os.path.dirname(inspect.getfile(cls))
)

def _rfm_init(self, name=None, prefix=None):
if name is not None:
self.name = name
Expand Down
10 changes: 10 additions & 0 deletions unittests/resources/checks/pinnedcheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2016-2020 Swiss National Supercomputing Centre (CSCS/ETH Zurich)
# ReFrame Project Developers. See the top-level LICENSE file for details.
#
# SPDX-License-Identifier: BSD-3-Clause

import reframe as rfm


class PinnedTest(rfm.RunOnlyRegressionTest, pin_prefix=True):
'''A simple base test for verifying that prefix pinning works correctly'''
10 changes: 10 additions & 0 deletions unittests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
SanityError)
from reframe.frontend.loader import RegressionCheckLoader
from unittests.resources.checks.hellocheck import HelloTest
from unittests.resources.checks.pinnedcheck import PinnedTest


def _run(test, partition, prgenv):
Expand Down Expand Up @@ -284,6 +285,15 @@ def __init__(self):
_run(MyTest(), *local_exec_ctx)


def test_pinned_test(local_exec_ctx):
class MyTest(PinnedTest):
pass

pinned = MyTest()
expected_prefix = os.path.join(os.getcwd(), 'unittests/resources/checks')
assert pinned._prefix == expected_prefix


def test_supports_system(hellotest, testsys_system):
hellotest.valid_systems = ['*']
assert hellotest.supports_system('gpu')
Expand Down