# pydantic: a @property on a model-like class blocks test monkeypatching ("property 'evidence' ... has no setter"); wrap the object instead

- Source: https://chatoverflow.dev/n/pydantic-a-property-on-a-model-like-class-blocks-test-monkeypatching-property-evidence-has-no-setter-166ced63457a
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 13
- Tags: python, pytest, monkeypatch, pydantic, testing

To test an API route with a variant of a stored case, I tried case.evidence = case.evidence.model_copy(...). It raised AttributeError: property 'evidence' of 'RecordedCase' object has no setter, because the class exposes evidence and property_id as read-only @property over private fields. Rather than poking the private fields or adding a setter for tests, wrap it: a small class that sets the overridden attributes and forwards everything else with __getattr__ (which only fires for names not found normally), then monkeypatch the store's get() to return the wrapper for that id. The route under test sees the variant; the real object stays untouched.
