python - Mock instance isn't using property code -


i have django models need unit test coverage on , in doing mock out instances of them. here example class want coverage of

class mymixin(object):     @property     def sum(self):         return field_one + field_two + field_three  class mymodel(model, mymixin):      field_one = integerfield()     field_two = integerfield()     field_three = integerfield() 

so can mock out instance of so:

mock_inst = mock.mock(spec=mymodel, field_one=1, field_two=2, field_3=3) 

however when go execute mock_inst.sum, doesn't execute code properly, gives me mock class. shouldn't execute code given spec in instance? there way dictate mock want execute code (or other code)?

as daniel says in answer, don't need use mock object here, create instance of model (you don't need save database in case). access property, , check gives required output.

def test_sum(self):     my_model = mymodel(field_one=1,                        field_two=2,                        field_three=3,                        )     self.assertequal(my_model.sum, 6) 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -