Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named mock

So I am trying to use unittest.mock to mock some of my methods in my unit tests. I do:

from unittest.mock import MagicMock f = open("data/static/mock_ffprobe_response") subprocess.check_output = MagicMock(return_value=f.read()) f.close() 

But I am getting:

ImportError: No module named mock 

I tried:

pip install mock 

It's still not working.

like image 924
Richard Knop Avatar asked Jul 16 '12 09:07

Richard Knop


1 Answers

unittest is a built-in module; mock is an external library (pre-3.3 betas, anyway). After installing mock via pip install, you import it not by using

from unittest.mock import MagicMock 

but

from mock import MagicMock 

Edit: mock has been included in the unittest module (since Python3.3), and can be imported by import unittest.mock.

like image 175
DSM Avatar answered Sep 23 '22 14:09

DSM