File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -61,6 +61,38 @@ class TestWithAssets(unittest.TestCase):
6161 self.assertIn("edges", config)
6262```
6363
64+ ### Testing Errors
65+
66+ Error cases *should* be tested, with `self.assertRaises`.
67+ Be careful when checking for error messages in the test case, as it makes it hard to update logs in the future.
68+ Some examples where we *should* check for error messages:
69+
70+ ```py
71+ # Example 1: Multiple errors - we should make sure we are raising when expected
72+ def foo():
73+ # Check when bar fails
74+ if not bar():
75+ raise ValueError("bar() failed!")
76+
77+ # Check when baz fails
78+ if not baz():
79+ raise ValueError("baz() failed!")
80+
81+ # Example 2: When the error message has load bearing use downstream - e.g. error reporting
82+ def qux():
83+ if not some_check():
84+ raise ValueError(f"Structured error: my/namespace/tries/10")
85+ ```
86+
87+ In all other cases, we should not be checking the exact error message.
88+ E.g. if the error message is formatted with the input:
89+
90+ ```py
91+ def assert_even(x: int):
92+ if not x % 2:
93+ raise ValueError(f"{x} is not even")
94+ ```
95+
6496### Integration Testing
6597
6698For integration tests that require cloud resources, add them to the `python/tests/integration` directory
You can’t perform that action at this time.
0 commit comments