From 91ec93f77ca62af0ead991f0a9358138c2248850 Mon Sep 17 00:00:00 2001 From: John Siirola Date: Fri, 8 Nov 2024 06:58:19 -0700 Subject: [PATCH] Add exception testing --- pyomo/common/tests/test_config.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pyomo/common/tests/test_config.py b/pyomo/common/tests/test_config.py index 4906382ae78..67bb93a7224 100644 --- a/pyomo/common/tests/test_config.py +++ b/pyomo/common/tests/test_config.py @@ -1863,7 +1863,18 @@ def test_default_function(self): c.value() c = ConfigValue('a', domain=int) - with self.assertRaisesRegex(ValueError, 'invalid value for configuration'): + with self.assertRaisesRegex( + ValueError, '(?s)invalid value for configuration.*casting a' + ): + c.value() + + # Test that if both the default and the result from calling the + # default raise exceptions, the propagated exception is from + # castig the original default: + c = ConfigValue(default=lambda: 'a', domain=int) + with self.assertRaisesRegex( + ValueError, "(?s)invalid value for configuration.*lambda" + ): c.value() def test_set_default(self):