Closed davidhassell closed 6 months ago
Hi David, did you want me to review this? Asking since it seems you might be waiting on a review but I am not assigned.
Hi Sadie - got any ideas on how to test on the value of the exception message string? Is that possible?
Hi @davidhassell, the way I am familiar with, and seems quite readable, is to update assertRaises
to assertRaisesRegex
: see https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertRaisesRegex. As an example using the test_Field
module, this diff
works to also test the error message:
diff --git a/cf/test/test_Field.py b/cf/test/test_Field.py
index 6f528642f..255ed45bd 100644
--- a/cf/test/test_Field.py
+++ b/cf/test/test_Field.py
@@ -393,7 +393,9 @@ class FieldTest(unittest.TestCase):
data=d,
)
- with self.assertRaises(Exception):
+ with self.assertRaisesRegex(
+ ValueError, "Can't set components=True and data=True"
+ ):
f.weights(components=True, data=True)
def test_Field_replace_construct(self):
It would be good to (eventually) go in and update more/most/all error checking to also test the messages in that way: shall I open an Issue for it?
+1 - I'll try that
Done: 3c2802f42f51c8fad667f257c9c6c4a2dd5f3d19
Fixes #731