def test():
    with mock.patch(MyClass, 'last_transaction') as mock_last_transaction:
        mock_last_transaction.__get__ = mock.Mock(return_value=Transaction())
myclass = MyClass()
print(myclass.last_transaction)
How to mock a readonly property with mock?