From f4448bce8fa119dc35bf7386a7683924cada511a Mon Sep 17 00:00:00 2001 From: Timothy Nunn Date: Wed, 4 Mar 2026 11:19:40 +0000 Subject: [PATCH] Hide model logs in regression test output --- tests/regression/test_process_input_files.py | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/regression/test_process_input_files.py b/tests/regression/test_process_input_files.py index 416375984..132ed2a0c 100644 --- a/tests/regression/test_process_input_files.py +++ b/tests/regression/test_process_input_files.py @@ -36,6 +36,27 @@ } +class ProcessModelFilter(logging.Filter): + def filter(self, record): + return 0 if record.levelno < logging.CRITICAL else 1 + + +@pytest.fixture +def hide_model_logs(): + """Hides model logs (process.model.*) from being reported if a regression test fails. + + This fixture adds a filter to all of the handlers on the root logger before the tests are run. + Modifying the logger handlers is crucial to avoid interfering with PROCESS model log system + which adds its own handers when PROCESS is run (hence why this is not done using the caplog fixture). + """ + filter_ = ProcessModelFilter(name="process.models") + for handler in logging.getLogger().handlers: + handler.addFilter(filter_) + yield + for handler in logging.getLogger().handlers: + handler.removeFilter(filter_) + + @dataclass class MFileVariableDifference: name: str @@ -245,6 +266,7 @@ def test_input_file( tracked_regression_test_assets, reg_tolerance: float, opt_params_only: bool, + hide_model_logs, ): """Tests each input file in the 'input_files' directory.