Skip to content

Commit ea8b0c7

Browse files
authored
Merge pull request #2948 from vkarak/enhancement/warn-unset-fixt-vars
[enhancement] Warn on unset variables in fixtures when using the `-S` option
2 parents f01551f + 839b354 commit ea8b0c7

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

reframe/core/decorators.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@ class TestRegistry:
5656
and the constructor arguments for the different instantiations of the
5757
test are stored as the dictionary value as a list of (args, kwargs)
5858
tuples.
59-
60-
For backward compatibility reasons, the registry also contains a set of
61-
tests to be skipped. The machinery related to this should be dropped with
62-
the ``required_version`` decorator.
6359
'''
6460

6561
def __init__(self):
66-
self._tests = dict()
62+
self._tests = {}
63+
self._unset_vars = {}
64+
65+
@property
66+
def unset_vars(self):
67+
return self._unset_vars
6768

6869
@classmethod
6970
def create(cls, test, *args, **kwargs):
@@ -85,6 +86,10 @@ def instantiate_all(self, reset_sysenv=0, external_vars=None):
8586
:param reset_sysenv: Reset valid_systems and valid_prog_environs after
8687
instantiating the tests. Bit 0 resets the valid_systems, bit 1
8788
resets the valid_prog_environs.
89+
90+
:param external_vars: Test variables to set in the instantiated
91+
fixtures.
92+
8893
'''
8994

9095
# We first instantiate the leaf tests and then walk up their
@@ -118,6 +123,7 @@ def instantiate_all(self, reset_sysenv=0, external_vars=None):
118123
# candidate tests; the leaf tests are consumed at the end of the
119124
# traversal and all instantiated tests (including fixtures) are stored
120125
# in `final_tests`.
126+
unset_vars = {}
121127
final_tests = []
122128
fixture_registry = FixtureRegistry()
123129
while leaf_tests:
@@ -132,7 +138,9 @@ def instantiate_all(self, reset_sysenv=0, external_vars=None):
132138
# Instantiate the new fixtures and update the registry
133139
new_fixtures = tmp_registry.difference(fixture_registry)
134140
if external_vars:
135-
_setvars(new_fixtures.uninst_tests(), external_vars)
141+
self._unset_vars.update(
142+
_setvars(new_fixtures.uninst_tests(), external_vars)
143+
)
136144

137145
leaf_tests = new_fixtures.instantiate_all()
138146
fixture_registry.update(new_fixtures)

reframe/frontend/cli.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,15 +1069,6 @@ def print_infoline(param, value):
10691069
f'{len(testcases)} remaining'
10701070
)
10711071

1072-
# Warn on any unset test variables for the final set of selected tests
1073-
for clsname in {type(tc.check).__name__ for tc in testcases}:
1074-
varlist = ', '.join(f'{v!r}' for v in loader.unset_vars(clsname))
1075-
if varlist:
1076-
printer.warning(
1077-
f'test {clsname!r}: '
1078-
f'the following variables were not set: {varlist}'
1079-
)
1080-
10811072
# Filter in failed cases
10821073
if options.failed:
10831074
if options.restore_session is None:
@@ -1195,6 +1186,16 @@ def _sort_testcases(testcases):
11951186
)
11961187
printer.verbose(f'Final number of test cases: {len(testcases)}')
11971188

1189+
# Warn on any unset test variables for the final set of selected tests
1190+
# including any dependencies
1191+
for clsname in {type(tc.check).__name__ for tc in testcases}:
1192+
varlist = ', '.join(f'{v!r}' for v in loader.unset_vars(clsname))
1193+
if varlist:
1194+
printer.warning(
1195+
f'test {clsname!r}: '
1196+
f'the following variables were not set: {varlist}'
1197+
)
1198+
11981199
# Disable hooks
11991200
for tc in testcases:
12001201
for h in options.hooks:

reframe/frontend/loader.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def load_from_module(self, module):
155155
if registry:
156156
candidate_tests = registry.instantiate_all(reset_sysenv,
157157
self._external_vars)
158+
self._unset_vars.update(registry.unset_vars)
158159
else:
159160
candidate_tests = []
160161

tutorials/cscs-webinar-2022/config/mysettings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
{
1313
'name': 'tresa',
1414
'descr': 'My laptop',
15-
'hostnames': ['tresa\.local'],
15+
'hostnames': ['tresa\.local', 'tresa'],
1616
'partitions': [
1717
{
1818
'name': 'default',

0 commit comments

Comments
 (0)