Skip to content

Commit

Permalink
test: #33 🚨 Add tests to ensure computed fields don't break anything
Browse files Browse the repository at this point in the history
  • Loading branch information
ddanier committed May 29, 2024
1 parent 7a2eb40 commit e8b5aa6
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/test_changedetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,3 +703,26 @@ def test_model_is_changed_if_marker_or_change_exists():
something.model_mark_changed("test")
assert something.model_has_changed
something.model_reset_changed()


@pytest.mark.skipif(PYDANTIC_V1, reason="pydantic v1 does not support computed fields")
def test_computed_fields_are_ignored():
class SomethingComputed(ChangeDetectionMixin, pydantic.BaseModel):
name: str

@pydantic.computed_field(return_type=str)
def computed(self) -> str:
return "computed"


something = SomethingComputed(name="test")

assert something.model_has_changed is False
assert something.model_changed_fields == set()
assert something.computed == "computed"

something.name = "new"

assert something.model_has_changed is True
assert something.model_changed_fields == {"name"}
assert something.computed == "computed"

0 comments on commit e8b5aa6

Please sign in to comment.