mocksafe.PropertyStubber
- class mocksafe.PropertyStubber(mock_object: SafeMock)
Used to set a MockProperty on an existing mock object.
You can obtain an instance of this class using
mocksafe.stub().Typically you wouldn’t instantiate or use this class directly.
- Example:
>>> from mocksafe import PropertyStubber, MockProperty, mock, stub
>>> class Philosopher: ... @property ... def meaning_of_life(self) -> str: ... return "TODO: discover the meaning of life"
>>> philosopher = mock(Philosopher)
>>> # Contrived example showing intermediate step: >>> property_stubber: PropertyStubber = stub(philosopher)
>>> # Set property attribute with a MockProperty[str] >>> property_stubber.meaning_of_life = MockProperty("")
>>> # More usual example: >>> stub(philosopher).meaning_of_life = MockProperty("")
See also:
mocksafe.MockProperty- __init__(mock_object: SafeMock)
Typically you wouldn’t instantiate or use this class directly, use
mocksafe.stub()to obtain an instance of this class instead.
Methods
__setattr__(prop_name, value)Magic method for setting
mocksafe.MockPropertyobjects as class attributes on the mocked object.