About Mock

A mock object substitutes and imitates a real object within a testing environment. It is a versatile and powerful tool for improving the quality of your tests. Basically we can replace the object which is specified as a first argument for “mock.patch” with MagicMock instance or any object you specified as a second argument. This is very useful when you write unit test to control other module behavior the module tested depends on.

To install

Create a env and install requirements:

$ sudo pip install virtualenv
$ which python3
$ virtualenv --python='path showed with which command' env
$ source env/bin/activate
$ pip install -r requirements.txt

To Run

pytest test_mock.py

Git

…or create a new repository on the command line

echo "# python-mock-experimentation" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/HandBoy/python-mock-experimentation.git
git push -u origin master

…or push an existing repository from the command line

git remote add origin https://github.com/HandBoy/python-mock-experimentation.git
git push -u origin master

References