Skip to content

Commit

Permalink
Bugfix #2830 develop fix missing log output (#2841)
Browse files Browse the repository at this point in the history
* Per #2830, skip closing of log handlers for METplusConfig objects that are created for copying values for process list instances so they are not closed before the end of the run.

* remove some output directories after tests are run
  • Loading branch information
georgemccabe authored Dec 18, 2024
1 parent d19d396 commit 235e0bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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

0 comments on commit 235e0bf

Please sign in to comment.