Skip to content

Commit 6f6340b

Browse files
sethfitzvcschapp
authored andcommitted
Strengthen weak assertions in string constraint tests
Replace `len(errors()) > 0` with error message assertions in hex color and no-whitespace invalid tests. The weak assertions only checked that validation failed, not that the correct error was raised.
1 parent 957b5e1 commit 6f6340b

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

packages/overture-schema-system/tests/field_constraint/test_string_constraints.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,7 @@ class TestModel(BaseModel):
311311
for color in invalid_colors:
312312
with pytest.raises(ValidationError) as exc_info:
313313
TestModel(color=color)
314-
# Just check that validation fails - message may vary
315-
assert len(exc_info.value.errors()) > 0
314+
assert "Invalid hexadecimal color format" in str(exc_info.value)
316315

317316
def test_no_whitespace_constraint_valid(self) -> None:
318317
"""Test NoWhitespaceConstraint with valid strings (no whitespace)."""
@@ -349,8 +348,7 @@ class TestModel(BaseModel):
349348
for ident in invalid_identifiers:
350349
with pytest.raises(ValidationError) as exc_info:
351350
TestModel(identifier=ident)
352-
# Just check that validation fails - message may vary
353-
assert len(exc_info.value.errors()) > 0
351+
assert "cannot contain whitespace" in str(exc_info.value)
354352

355353

356354
class TestJsonSchemaGeneration:

0 commit comments

Comments
 (0)