I found that the following change worked: @mock.patch('dao.dao.execute_ldap_search') def test_find_by_last_first_comma(self, mock_dao): # setup the mock mock_dao.return_value = self.ldap_person_response
Daniel On Monday, March 9, 2015 at 10:28:20 AM UTC-5, Daniel wrote: > I have a dao.py module with a dao class declared and I want to use mock to > set a return value for a dao function, dao.execute_ldap_search(). > > import mock > import unittest > import model, dao > > class TestPeopleDAO(unittest.TestCase): > > ldap_person_response = SOME_DICT > > @mock.patch('dao.dao') > def test_find_by_last_first_comma(self, mock_dao): > # setup the mock > mock_dao.execute_ldap_search.return_value = self.ldap_person_response > > persondao = dao.person_dao() > persondao.find_by_last_first_comma('name', '', '') > self.assertEqual(len(persondao),1,"Wrong number of objects returned.") > self.assertEqual(persondao[0].givenName, "FirstName", "Failed to > parse response.") > > if __name__ == '__main__': > unittest.main() > > When I run this, it fails when calling execute_ldap_search because it really > calls it. I was expecting it to just return the value I specified. What am I > doing wrong? -- https://mail.python.org/mailman/listinfo/python-list