title: Python unittest mock ... mock a module statement
body: <p>I'm having difficuly getting my head around python's mock test methodology.</p>
  
  <p>I want to do some mocking on <a href="https://github.com/powlo/weather.metoffice/blob/master/src/metoffice/setlocation.py" rel="nofollow">this file</a>.</p>
  
  <p>Since packages xbmc, xbmcaddon and xbmcgui cannot be imported in a normal python environment I've managed to mock them out like this:</p>
  
  <pre><code>class XBMCTestCase(unittest.TestCase):    
      def setUp(self):
          #Mock up any calls to modules that cannot be imported
          self.xbmc = Mock()
          self.xbmcgui = Mock()
          self.xbmcaddon = Mock()
  
          modules = {
              'xbmc' : self.xbmc,
              'xbmcgui': self.xbmcgui,
              'xbmcaddon': self.xbmcaddon
              }
          self.module_patcher = patch.dict('sys.modules', modules) #@UndefinedVariable
          self.module_patcher.start()
  </code></pre>
  
  <p>See it in action <a href="https://github.com/powlo/weather.metoffice/blob/master/src/test/test_urlcache.py" rel="nofollow">here</a>.</p>
  
  <p>So when I import setlocation.py I get an error like this:</p>
  
  <pre><code>  File "/home/paulo/workspace/weather.metoffice/src/metoffice/utils/utilities.py", line 21, in &lt;module&gt;
      CACHE_FOLDER = os.path.join(ADDON_DATA_PATH, 'cache')
    File "/usr/lib/python2.7/posixpath.py", line 78, in join
      path +=  b
  TypeError: unsupported operand type(s) for +=: 'Mock' and 'str'
  </code></pre>
  
  <p>Even if I mock out 'metoffice.utils' (by adding it to the list of modules in the patch created at setup) I get a similar error in <code>setlocation.py</code></p>
  
  <pre><code>  File "/home/paulo/workspace/weather.metoffice/src/metoffice/setlocation.py", line 32, in &lt;module&gt;
      GEOIP_PROVIDER = int(__addon__.getSetting('GeoIPProvider'))
  TypeError: int() argument must be a string or a number, not 'Mock'
  </code></pre>
  
  <p>So I need <code>__addon__.getSetting()</code> to return a string.</p>
  
  <p>Any ideas?</p>
  
  <p>All attempts have failed, but I don't think I have a full grasp of the capabilities of the mock package.</p>
  
  <p>Note I'm on Python 2.7.3 with <a href="https://pypi.python.org/pypi/mock" rel="nofollow">mock 1.0.1</a></p>