Skip to content

Commit a48144b

Browse files
Ask the robots to not check error messages so explicitely (#402)
Co-authored-by: kmontemayor <kyle.e.montemayor@gmail.com>
1 parent 3ef96a7 commit a48144b

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

.cursor/rules/testing-patterns.mdc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff 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

6698
For integration tests that require cloud resources, add them to the `python/tests/integration` directory

0 commit comments

Comments
 (0)