Skip to content

Commit 0bc03dc

Browse files
author
Vasileios Karakasis
authored
Merge branch 'master' into feat/deprecate-parameterized_test
2 parents 57008da + 15d37da commit 0bc03dc

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

reframe/core/logging.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,10 @@ def error(self, msg, *args, **kwargs):
408408
return self.log(ERROR, msg, *args, **kwargs)
409409

410410
def warning(self, msg, *args, **kwargs):
411-
return self.log(WARNING, msg, *args, **kwargs)
411+
self.log(WARNING, msg, *args, **kwargs)
412412

413413
def info(self, msg, *args, **kwargs):
414-
return self.log(INFO, msg, *args, **kwargs)
414+
self.log(INFO, msg, *args, **kwargs)
415415

416416
def verbose(self, message, *args, **kwargs):
417417
self.log(VERBOSE, message, *args, **kwargs)
@@ -423,6 +423,10 @@ def debug2(self, message, *args, **kwargs):
423423
self.log(DEBUG2, message, *args, **kwargs)
424424

425425

426+
# This is a cache for warnings that we don't want to repeat
427+
_WARN_ONCE = set()
428+
429+
426430
class LoggerAdapter(logging.LoggerAdapter):
427431
def __init__(self, logger=None, check=None):
428432
super().__init__(
@@ -550,7 +554,13 @@ def debug2(self, message, *args, **kwargs):
550554
def verbose(self, message, *args, **kwargs):
551555
self.log(VERBOSE, message, *args, **kwargs)
552556

553-
def warning(self, message, *args, **kwargs):
557+
def warning(self, message, *args, cache=False, **kwargs):
558+
if cache:
559+
if message in _WARN_ONCE:
560+
return
561+
562+
_WARN_ONCE.add(message)
563+
554564
message = '%s: %s' % (sys.argv[0], message)
555565
if self.colorize:
556566
message = color.colorize(message, color.YELLOW)
@@ -594,6 +604,7 @@ def __init__(self, check=None, level=DEBUG):
594604
self._orig_logger = _context_logger
595605
if check is not None:
596606
_context_logger = LoggerAdapter(_logger, check)
607+
_context_logger.colorize = self._orig_logger.colorize
597608

598609
def __enter__(self):
599610
return _context_logger

reframe/core/modules.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,14 @@ def unload_all(self):
10081008
class NoModImpl(ModulesSystemImpl):
10091009
'''A convenience class that implements a no-op a modules system.'''
10101010

1011+
def _warn(self, msg):
1012+
getlogger().warning(
1013+
f"no modules system is set: {msg}: "
1014+
f"check the 'modules_system' configuration "
1015+
f"parameter for your system",
1016+
cache=True
1017+
)
1018+
10111019
def available_modules(self, substr):
10121020
return []
10131021

@@ -1021,10 +1029,10 @@ def _execute(self, cmd, *args):
10211029
return ''
10221030

10231031
def load_module(self, module):
1024-
pass
1032+
self._warn(f'module {module.name!r} will not be loaded')
10251033

10261034
def unload_module(self, module):
1027-
pass
1035+
self._warn(f'module {module.name!r} will not be unloaded')
10281036

10291037
def is_module_loaded(self, module):
10301038
#
@@ -1043,21 +1051,23 @@ def modulecmd(self, *args):
10431051
return ''
10441052

10451053
def unload_all(self):
1046-
pass
1054+
self._warn('no module will be purged')
10471055

10481056
def searchpath(self):
10491057
return []
10501058

10511059
def searchpath_add(self, *dirs):
1052-
pass
1060+
self._warn('MODULEPATH will not be modified')
10531061

10541062
def searchpath_remove(self, *dirs):
1055-
pass
1063+
self._warn('MODULEPATH will not be modified')
10561064

10571065
def emit_load_instr(self, module):
1066+
self._warn(f'module {module.name!r} will not be loaded')
10581067
return []
10591068

10601069
def emit_unload_instr(self, module):
1070+
self._warn(f'module {module.name!r} will not be unloaded')
10611071
return []
10621072

10631073

unittests/test_logging.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,18 @@ def test_handler_noappend(make_exec_ctx, config_file, logfile):
328328
assert _found_in_logfile('bar', logfile)
329329

330330

331+
def test_warn_once(default_exec_ctx, logfile):
332+
rlog.configure_logging(rt.runtime().site_config)
333+
rlog.getlogger().warning('foo', cache=True)
334+
rlog.getlogger().warning('foo', cache=True)
335+
rlog.getlogger().warning('foo', cache=True)
336+
_flush_handlers()
337+
_close_handlers()
338+
339+
with open(logfile, 'rt') as fp:
340+
assert len(re.findall('foo', fp.read())) == 1
341+
342+
331343
def test_date_format(default_exec_ctx, logfile):
332344
rlog.configure_logging(rt.runtime().site_config)
333345
rlog.getlogger().warning('foo')

0 commit comments

Comments
 (0)