Skip to content
Advertisement

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:

JavaScript

But I am getting:

JavaScript

I tried:

JavaScript

It’s still not working.

Advertisement

Answer

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

JavaScript

but

JavaScript

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

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement