Skip to content
Draft
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
22 changes: 22 additions & 0 deletions tests/regression/test_process_input_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand Down