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
17 changes: 15 additions & 2 deletions reframe/core/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#

import functools
import inspect
import types
import collections

Expand Down Expand Up @@ -821,7 +822,7 @@ def loggable_attrs(cls):
return sorted(loggable_props + loggable_vars + loggable_params)


def make_test(name, bases, body, methods=None, **kwargs):
def make_test(name, bases, body, methods=None, module=None, **kwargs):
'''Define a new test class programmatically.

Using this method is completely equivalent to using the :keyword:`class`
Expand Down Expand Up @@ -890,13 +891,18 @@ def validate(obj):
:param methods: A list of functions to be bound as methods to the class
that is being created. The functions will be bound with their original
name.
:param module: The module name of the new test class.
If :obj:`None`, the module of the caller will be used.
:param kwargs: Any keyword arguments to be passed to the
:class:`RegressionTestMeta` metaclass.

.. versionadded:: 3.10.0

.. versionchanged:: 3.11.0
Added the ``methods`` arguments.
Added the ``methods`` argument.

.. versionadded:: 4.2
Added the ``module`` argument.

'''
namespace = RegressionTestMeta.__prepare__(name, bases, **kwargs)
Expand All @@ -915,4 +921,11 @@ def validate(obj):
namespace.reset(k)

cls = RegressionTestMeta(name, bases, namespace, **kwargs)

if not module:
# Set the test's module to be that of our callers
caller = inspect.currentframe().f_back
module = caller.f_globals['__name__']

cls.__module__ = module
return cls
17 changes: 17 additions & 0 deletions unittests/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1835,9 +1835,26 @@ def test_make_test_without_builtins(local_exec_ctx):
)

assert hello_cls.__name__ == 'HelloTest'
assert hello_cls.__module__ == 'unittests.test_pipeline'
_run(hello_cls(), *local_exec_ctx)


def test_make_test_with_module():
hello_cls = make_test(
'HelloTest', (rfm.RunOnlyRegressionTest,),
{
'valid_systems': ['*'],
'valid_prog_environs': ['*'],
'executable': 'echo',
'sanity_patterns': sn.assert_true(1)
},
module='foo'
)

assert hello_cls.__name__ == 'HelloTest'
assert hello_cls.__module__ == 'foo'


def test_make_test_with_builtins(local_exec_ctx):
class _X(rfm.RunOnlyRegressionTest):
valid_systems = ['*']
Expand Down