Mocking a function throughout a project
Question: I would like to [mock](http://pypi.python.org/pypi/mock) a certain function in
a utility module throughout my project, as part of a testing suite. I could of
course patch and mock this function for each module using it, but there are a
lot of these and it would be non-robust and tedious.

Is there a way to patch\mock it throughout the project?  
If I patch and mock it in the utility module before any other module imports
it, would the function be imported or the mock?


Answer: Sure, just `import module` in your script, patch it, then import the other
modules that use it and invoke whatever you need to test in them. Modules are
imported only once in a session; additional `import` statements use the
already-imported module. So the other modules that import the patched module
will automatically get the patches.

