diff --git a/reframe/core/pipeline.py b/reframe/core/pipeline.py index 43b362de71..09c0286958 100644 --- a/reframe/core/pipeline.py +++ b/reframe/core/pipeline.py @@ -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 @@ -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 diff --git a/unittests/resources/checks/pinnedcheck.py b/unittests/resources/checks/pinnedcheck.py new file mode 100644 index 0000000000..5be06b375c --- /dev/null +++ b/unittests/resources/checks/pinnedcheck.py @@ -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''' diff --git a/unittests/test_pipeline.py b/unittests/test_pipeline.py index d83d79144f..8fa727e95f 100644 --- a/unittests/test_pipeline.py +++ b/unittests/test_pipeline.py @@ -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): @@ -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')