jeudi 4 juin 2015

Writing the body of a Mock function

I am a beginner in Python and I have been given the task of writing unit tests. I have the following statement: return self.collection.insert(data) The function insert() is of Mongo DB which inserts the data into the database. I am writing a test for testing insert(), I want to create and write into a mock function of insert(), so as to not have dependency on the database. I am stuck as to where to write the function body. This is what I've done till now: collection = Mock() collection.insert = Mock(return_value={"a": 1}) The above creates the mock function with the return value. What should I do if I want to give the function a body? Also, I don't have access to the original insert() function.

Aucun commentaire:

Enregistrer un commentaire