Skip to content

Commit

Permalink
Handle exception in show_output task method
Browse files Browse the repository at this point in the history
  • Loading branch information
maddenp-noaa committed Oct 31, 2024
1 parent 17e010c commit acca926
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/uwtools/drivers/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,10 @@ def show_output(self):
Show the output to be created by this component.
"""
yield self.taskname("expected output")
print(json.dumps(self.output, indent=2, sort_keys=True))
try:
print(json.dumps(self.output, indent=2, sort_keys=True))
except UWConfigError as e:
log.error(e)
yield asset(None, lambda: True)

@task
Expand Down
7 changes: 7 additions & 0 deletions src/uwtools/tests/drivers/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,13 @@ def test_driver_show_output(capsys, config):
assert capsys.readouterr().out.strip() == dedent(expected).strip()


def test_driver_show_output_fail(caplog, config):
with patch.object(ConcreteDriverTimeInvariant, "output", new_callable=PropertyMock) as output:
output.side_effect = UWConfigError("FAIL")
ConcreteDriverTimeInvariant(config).show_output()
assert "FAIL" in caplog.messages


@mark.parametrize(
"base_file,update_values,expected",
[
Expand Down

0 comments on commit acca926

Please sign in to comment.