title: Mock patches don't work more than once
body: <p>I cannot get mock's patches to work. In the following code, only the first <code>assertEqual</code> inside <code>test_base</code> succeeds. If I swap the first with the second, again only the first one succeeds.</p>
  
  <pre><code>import os
  import mock
  
  def fake_isfile(filename):
      if filename == 'file.py':
          return True
      return False
  
  
  def fake_walk():
      yield '.', ['tests', 'sub', '.hid'], ['tox.ini', 'amod.py', 'test_all.py']
      yield './tests', [], ['test_amod.py', 'run.py', '.hid.py']
      yield './sub', [], ['amod.py', 'bmod.py']
  
  
  class TestIterFilenames(unittest.TestCase):
  
      def setUp(self):
          self.iter_files = lambda *a, **kw: list(tools.iter_filenames(*a, **kw))
  
      def test_stdin(self):
          self.assertEqual(self.iter_files(['-']), ['-'])
  
      @mock.patch('tools.os.path')
      @mock.patch('tools.os')
      def test_all(self, os_mod, os_path_mod):
          os_path_mod.normpath = os.path.normpath
          os_path_mod.basename = os.path.basename
          os_path_mod.join = os.path.join
          os_path_mod.isfile.side_effect = fake_isfile
          os_mod.walk.return_value = fake_walk()
  
          self.assertEqual(self.iter_files(['file.py', 'random/path']),
                           ['file.py', 'amod.py', 'test_all.py',
                            'tests/test_amod.py', 'tests/run.py', 'sub/amod.py',
                            'sub/bmod.py'])
  
          self.assertEqual(self.iter_files(['file.py', 'random/path'],
                                           'test_.*'),
                           ['file.py', 'amod.py', 'tests/test_amod.py',
                            'tests/run.py', 'sub/amod.py', 'sub/bmod.py'])
  </code></pre>
  
  <p>I looked into the documentation, and I found that to cleanup after every test method I had to do the following:</p>
  
  <pre><code>import os
  import mock
  
  def fake_isfile(filename):
      if filename == 'file.py':
          return True
      return False
  
  
  def fake_walk():
      yield '.', ['tests', 'sub', '.hid'], ['tox.ini', 'amod.py', 'test_all.py']
      yield './tests', [], ['test_amod.py', 'run.py', '.hid.py']
      yield './sub', [], ['amod.py', 'bmod.py']
  
  
  class TestIterFilenames(unittest.TestCase):
  
      def setUp(self):
          self.iter_files = lambda *a, **kw: list(tools.iter_filenames(*a, **kw))
  
          self.patcher1 = mock.patch('radon.cli.tools.os.path')
          self.patcher2 = mock.patch('radon.cli.tools.os')
  
          os_path_mod = self.patcher1.start()
          os_mod = self.patcher2.start()
          os_path_mod.normpath = os.path.normpath
          os_path_mod.basename = os.path.basename
          os_path_mod.join = os.path.join
          os_path_mod.isfile.side_effect = fake_isfile
          os_mod.walk.return_value = fake_walk()
  
      def tearDown(self):
          self.patcher1.stop()
          self.patcher2.stop()
  
      def test_base(self):
          self.assertEqual(self.iter_files(['file.py', 'random/path']),
                           ['file.py', 'amod.py', 'test_all.py',
                            'tests/test_amod.py', 'tests/run.py', 'sub/amod.py',
                            'sub/bmod.py'])
  
      def test_exclude(self):
          self.assertEqual(self.iter_files(['file.py', 'random/path'],
                                           'test_.*'),
                           ['file.py', 'amod.py', 'tests/test_amod.py',
                            'tests/run.py', 'sub/amod.py', 'sub/bmod.py'])
  </code></pre>
  
  <p>However, even in this case the second test method fails because <code>fake_walk</code> <strong>does not get called</strong> (I am sure of this).</p>