From acca926b4e8508a0f092124d5da3bca3601d0fcb Mon Sep 17 00:00:00 2001 From: Paul Madden Date: Thu, 31 Oct 2024 18:42:10 +0000 Subject: [PATCH] Handle exception in show_output task method --- src/uwtools/drivers/driver.py | 5 ++++- src/uwtools/tests/drivers/test_driver.py | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/uwtools/drivers/driver.py b/src/uwtools/drivers/driver.py index 107fd800a..dfdf80d44 100644 --- a/src/uwtools/drivers/driver.py +++ b/src/uwtools/drivers/driver.py @@ -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 diff --git a/src/uwtools/tests/drivers/test_driver.py b/src/uwtools/tests/drivers/test_driver.py index 25dd0f625..9f33c2961 100644 --- a/src/uwtools/tests/drivers/test_driver.py +++ b/src/uwtools/tests/drivers/test_driver.py @@ -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", [