Skip to content

Commit

Permalink
Add a local pytest plugin to allow overwriting Loki log level
Browse files Browse the repository at this point in the history
  • Loading branch information
reuterbal committed Oct 14, 2024
1 parent 44df609 commit 398b668
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# (C) Copyright 2018- ECMWF.
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.

"""
Local pytest plugin to add bespoke pytest extensions for Loki
See the pytest documentation for more details:
https://docs.pytest.org/en/stable/how-to/writing_plugins.html#local-conftest-plugins
"""

from loki.config import config as loki_config


def pytest_addoption(parser, pluginmanager): # pylint: disable=unused-argument
"""
Add options to the pytest CLI
Additional options can be specified via ``parser.addoption`` using the same signature as
:any:`argparse.ArgumentParser.add_argument`.
For Loki, we add ``--loki-log-level`` to overwrite the log level in :any:`loki.logging`.
"""
parser.addoption('--loki-log-level', dest='LOKI_LOG_LEVEL', default='INFO',
help='Change the Loki log level (ERROR, WARNING, INFO, PERF, DETAIL, DEBUG)')


def pytest_configure(config):
"""
Apply configuration changes
This function is invoked after all command line options have been processed
"""
loki_config['log-level'] = config.option.LOKI_LOG_LEVEL

0 comments on commit 398b668

Please sign in to comment.