Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix #2830 develop fix missing log output #2841

Merged
merged 2 commits into from
Dec 18, 2024
Merged
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
10 changes: 10 additions & 0 deletions internal/tests/pytests/util/run_util/test_run_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
'INPUT_THRESH',
]

def remove_output_base(config):
config_output_base = config.getdir("OUTPUT_BASE")
if config_output_base and os.path.exists(config_output_base):
ru.shutil.rmtree(config_output_base)

def get_run_util_configs(conf_name):
script_dir = os.path.dirname(__file__)
Expand Down Expand Up @@ -130,6 +134,7 @@ def test_pre_run_setup():
expected_stage = os.path.join(actual.get('config', 'OUTPUT_BASE'), 'stage')
assert actual.get('config', 'STAGING_DIR') == expected_stage
assert actual.get('user_env_vars', 'GODS_OF_WEATHER') == 'Indra_Thor_Zeus'
remove_output_base(actual)


@pytest.mark.util
Expand All @@ -139,6 +144,7 @@ def test_pre_run_setup_env_vars():
actual = ru.pre_run_setup(conf_inputs)
assert actual.env['MY_ENV_VAR'] == '42'
assert actual.get('config', 'OMP_NUM_THREADS') == '4'
remove_output_base(actual)


@pytest.mark.util
Expand Down Expand Up @@ -262,6 +268,7 @@ def test_run_metplus(capfd, config_dict, expected, check_err):
else:
assert err == ''

remove_output_base(config)

@pytest.mark.parametrize(
"side_effect,return_value,check_err",
Expand All @@ -285,6 +292,8 @@ def test_run_metplus_errors(capfd, side_effect, return_value, check_err):
else:
assert err == check_err

remove_output_base(config)


@pytest.mark.util
def test_get_wrapper_instance(metplus_config):
Expand All @@ -308,6 +317,7 @@ def test_get_wrapper_instance_raises(capfd, side_effect, check_err):
assert actual == None
out, err = capfd.readouterr()
assert check_err in err
remove_output_base(config)


@pytest.mark.util
Expand Down
5 changes: 5 additions & 0 deletions metplus/util/config_metplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ def __init__(self, conf=None, run_id=None):
super().__init__(conf)
self._cycle = None
self.run_id = run_id if run_id else str(uuid.uuid4())[0:8]
# if run ID is specified, this is a copy of a config
self.is_copy = run_id is not None
self._logger = logging.getLogger(f'metplus.{self.run_id}')
# config.logger is called in wrappers, so set this name
# so the code doesn't break
Expand All @@ -475,6 +477,9 @@ def __init__(self, conf=None, run_id=None):

def __del__(self):
"""!When object is deleted, close and remove all log handlers"""
# do not close log handlers if this is a copied config object
if self.is_copy:
return
handlers = self.logger.handlers[:]
for handler in handlers:
self.logger.removeHandler(handler)
Expand Down
Loading