unit testing - Stubbing vs Mocking in Python -


I want to duplicate or stub the function for testing. I am convinced that if I have the correct vocabulary, then correct me Let me say if I am wrong, but I use a joke library to make a counterfeit thing as a fake and hope that what criteria it will get and what it will be, etc. I think that I want to have a little bit of ridicule for everyone, this is a good / stubbed method to do, a fixed price is returned.

I think the answer to 'joke without library' What I can see, this is what I need. It's light and simple and you do not have to roam with all the fun options for ordinary cases.

My question is, Is it safe to do this? The above question seems to overwrite the memory representation of a law, and it does not seem right that it has been accepted by the dragon community? Or is it encouraged to use the proper joke library all the time?

Edit If you do not reassign the method in the block at the end, what kind of frightening things are said in the answer connected?

The main reason I wanted to stutter the method, there is a need to worry about the fake and it Have to go through the install. Although I think that the use of the Fake library shows an excellent way to do annotation, it makes it very easy by manually making an example duplicate here There is an excerpt:

  #! / Usr / bin / env dragon # - * - coding: UTF-8 - * - Import OS import OS. Path def RM (filename): If os.path.isfile (filename): os.remove (filename)  

rmtest.py

  #! / Usr / bin / env python # - * - coding: UTF-8 - * - mymodule import rm import counterfeit import unit class rmTestCase (unittest.TestCase): @ mock.patch ('mymodule.os.path') @mock Patch ('mymodule.os') def test_rm (self, mock_os, mock_path): # set mock mac_path.Sface.Return_value = wrong rm ("any path") # test that the call to remove was not called. Self.assertfalse (mock_os.remove.called, "if file does not exist, can not be removed.") #make_path.isfile.return_value = true rm ("any path") mock_os.remove .assert_called_with ("any path")  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -