Skip to content

Tag: python-import

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: But I am getting: I tried: It’s still not working. 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 but Edit:…

Sibling package imports

I’ve tried reading through questions about sibling imports and even the package documentation, but I’ve yet to find an answer. With the following structure: How can the scripts in the examples and tests directories import from the api module and be run from the commandline? Also, I’d like to…

How do I unload (reload) a Python module?

I have a long-running Python server and would like to be able to upgrade a service without restarting the server. What’s the best way do do this? Answer You can reload a module when it has already been imported by using importlib.reload(): In Python 2, reload was a builtin. In Python 3, it was moved to …