Skip to content
Open
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
21 changes: 21 additions & 0 deletions docs/manpage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,14 @@ Miscellaneous options

This option can also be set using the :envvar:`RFM_VERBOSE` environment variable or the :attr:`~config.general.verbose` general configuration parameter.

.. option:: --warn-as-error

Treat warnings as errors.

This option can also be set using the :envvar:`RFM_WARN_AS_ERROR` environment variable.

.. versionadded:: 4.10


.. _test_naming_scheme:

Expand Down Expand Up @@ -2633,6 +2641,19 @@ Whenever an environment variable is associated with a configuration option, its
================================== ==================


.. envvar:: RFM_WARN_AS_ERROR

Treat warnings as errors.

.. table::
:align: left

================================== ==================
Associated command line option :option:`--warn-as-error`
Associated configuration parameter N/A
================================== ==================


.. _manpage-configuration:

Configuration
Expand Down
4 changes: 4 additions & 0 deletions reframe/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ class ReferenceParseError(ReframeError):
'''


class WarningAsError(ReframeError):
'''Raised when a warning is treated as an error.'''


def user_frame():
'''Return the first user frame as a :py:class:`FrameInfo` object.

Expand Down
10 changes: 8 additions & 2 deletions reframe/core/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import reframe.utility.color as color
import reframe.utility.jsonext as jsonext
import reframe.utility.osext as osext
from reframe.core.exceptions import ConfigError, LoggingError, what
from reframe.core.exceptions import (ConfigError, LoggingError,
WarningAsError, what)
from reframe.core.warnings import suppress_deprecations
from reframe.utility import is_trivially_callable
from reframe.utility.profile import TimeProfiler
Expand Down Expand Up @@ -903,6 +904,7 @@ def __init__(self, logger=None, check=None):
)
self.check = check
self.colorize = False
self.warn_as_error = False

def setLevel(self, level):
if self.logger:
Expand Down Expand Up @@ -999,6 +1001,9 @@ def verbose(self, message, *args, **kwargs):
self.log(VERBOSE, message, *args, **kwargs)

def warning(self, message, *args, cache=False, **kwargs):
if self.warn_as_error:
raise WarningAsError(message)

if cache:
if message in _WARN_ONCE:
return
Expand Down Expand Up @@ -1082,7 +1087,7 @@ def __exit__(self, exc_type, exc_value, traceback):
_context_logger = self._orig_logger


def configure_logging(site_config):
def configure_logging(site_config, warn_as_error=False):
global _logger, _context_logger, _perf_logger

if site_config is None:
Expand All @@ -1095,6 +1100,7 @@ def configure_logging(site_config):
_logger = _create_logger(site_config, 'handlers$', 'handlers')
_perf_logger = _create_logger(site_config, 'handlers_perflog')
_context_logger = LoggerAdapter(_logger)
_context_logger.warn_as_error = warn_as_error


def log_files():
Expand Down
7 changes: 6 additions & 1 deletion reframe/frontend/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,11 @@ def main():
'-q', '--quiet', action='count', default=0,
help='Decrease verbosity level of output',
)
misc_options.add_argument(
'--warn-as-error', action='store_true',
help='Treat warnings as errors',
envvar='RFM_WARN_AS_ERROR'
)

# Options not associated with command-line arguments
argparser.add_argument(
Expand Down Expand Up @@ -1076,7 +1081,7 @@ def restrict_logging():
options = argparser.parse_args(namespace=options.cmd_options)
options.update_config(site_config)

logging.configure_logging(site_config)
logging.configure_logging(site_config, options.warn_as_error)
except (OSError, errors.ConfigError) as e:
printer.error(f'failed to load configuration: {e}')
printer.info(logfiles_message())
Expand Down
11 changes: 11 additions & 0 deletions unittests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,17 @@ def test_testlib_inherit_fixture_in_different_files(run_reframe):
assert 'FAILED' not in stdout


def test_warn_as_error(run_reframe):
returncode, stdout, stderr = run_reframe(
checkpath=['/unknown/path'],
more_options=['--warn-as-error']
)
assert 'Traceback' not in stdout
assert 'Traceback' not in stderr
assert returncode == 1
assert 'warning as error' in stdout


@pytest.fixture(params=['csv', 'plain', 'pretty'])
def table_format(request):
return request.param
Expand Down
Loading